diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
commit | adaa36dbec1ce9aaafd61873b9d3d898a8c240cf (patch) | |
tree | 4c81e8f5983c3d696a636e2cc433ce7c0a9c3dd8 /tests/linda_perf.lua | |
parent | 1d310e6ecb6e156598337612f16573d9cd284f5e (diff) | |
download | lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.gz lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.bz2 lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.zip |
Bring all interesting fixes from the C++ implementation back into the C implementation
Diffstat (limited to 'tests/linda_perf.lua')
-rw-r--r-- | tests/linda_perf.lua | 165 |
1 files changed, 84 insertions, 81 deletions
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index a170b01..61b8f05 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua | |||
@@ -1,38 +1,62 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes" |
2 | lanes.configure{ with_timers = false} | 2 | lanes.configure{ with_timers = false, keepers_gc_threshold=30000 } |
3 | |||
4 | -- set TEST1, PREFILL1, FILL1, TEST2, PREFILL2, FILL2 from the command line | ||
3 | 5 | ||
4 | -- Lua 5.1/5.2 compatibility | 6 | -- Lua 5.1/5.2 compatibility |
5 | local table_unpack = unpack or table.unpack | 7 | local table_unpack = unpack or table.unpack |
6 | 8 | ||
9 | local finalizer = function(err, stk) | ||
10 | if err == lanes.cancel_error then | ||
11 | -- note that we don't get the cancel_error when running wrapped inside a protected call if it doesn't rethrow it | ||
12 | print(" laneBody after cancel" ) | ||
13 | elseif err then | ||
14 | print(" laneBody error: "..tostring(err)) | ||
15 | else | ||
16 | print(" laneBody finalized") | ||
17 | end | ||
18 | end | ||
19 | |||
20 | --################################################################################################## | ||
21 | |||
7 | -- this lane eats items in the linda one by one | 22 | -- this lane eats items in the linda one by one |
8 | local eater = function( l, loop) | 23 | local eater = function( l, loop) |
24 | set_finalizer(finalizer) | ||
9 | -- wait for start signal | 25 | -- wait for start signal |
10 | l:receive( "go") | 26 | l:receive( "go") |
11 | -- eat data one by one | 27 | -- eat data one by one |
12 | for i = 1, loop do | 28 | for i = 1, loop do |
13 | local val, key = l:receive( "key") | 29 | local key, val = l:receive( "key") |
14 | --print( val) | 30 | -- print("eater:", val) |
15 | end | 31 | end |
16 | -- print "loop is over" | 32 | -- print "loop is over" |
17 | key, val = l:receive( "done") | 33 | key, val = l:receive( "done") |
18 | -- print( val) | 34 | print("eater: done ("..val..")") |
19 | end | 35 | end |
20 | 36 | ||
37 | --################################################################################################## | ||
38 | |||
21 | -- this lane eats items in the linda in batches | 39 | -- this lane eats items in the linda in batches |
22 | local batched = function( l, loop, batch) | 40 | local gobbler = function( l, loop, batch) |
41 | set_finalizer(finalizer) | ||
23 | -- wait for start signal | 42 | -- wait for start signal |
24 | l:receive( "go") | 43 | l:receive( "go") |
25 | -- eat data in batches | 44 | -- eat data in batches |
26 | for i = 1, loop/batch do | 45 | for i = 1, loop/batch do |
27 | l:receive( l.batched, "key", batch) | 46 | l:receive( l.batched, "key", batch) |
47 | -- print("gobbler:", batch) | ||
28 | end | 48 | end |
29 | print "loop is over" | 49 | print "loop is over" |
30 | key, val = l:receive( "done") | 50 | key, val = l:receive( "done") |
31 | print( val) | 51 | print("gobbler: done ("..val..")") |
32 | end | 52 | end |
33 | 53 | ||
54 | --################################################################################################## | ||
55 | |||
34 | local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) | 56 | local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) |
35 | local lane_batched_gen = lanes.gen( "*", {priority = 3}, batched) | 57 | local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) |
58 | |||
59 | --################################################################################################## | ||
36 | 60 | ||
37 | -- main thread writes data while a lane reads it | 61 | -- main thread writes data while a lane reads it |
38 | local function ziva( preloop, loop, batch) | 62 | local function ziva( preloop, loop, batch) |
@@ -46,7 +70,7 @@ local function ziva( preloop, loop, batch) | |||
46 | print( "stored " .. l:count( "key") .. " items in the linda before starting consumer lane") | 70 | print( "stored " .. l:count( "key") .. " items in the linda before starting consumer lane") |
47 | if batch > 0 then | 71 | if batch > 0 then |
48 | if l.batched then | 72 | if l.batched then |
49 | lane = lane_batched_gen( l, top, batch) | 73 | lane = lane_gobbler_gen( l, top, batch) |
50 | else | 74 | else |
51 | print "no batch support in this version of Lanes" | 75 | print "no batch support in this version of Lanes" |
52 | lane = lane_eater_gen( l, top) | 76 | lane = lane_eater_gen( l, top) |
@@ -63,7 +87,9 @@ local function ziva( preloop, loop, batch) | |||
63 | for i = 1, batch do | 87 | for i = 1, batch do |
64 | table.insert( batch_values, i) | 88 | table.insert( batch_values, i) |
65 | end | 89 | end |
90 | local batch_send_log = "main: sending "..batch.." values" | ||
66 | local batch_send = function() | 91 | local batch_send = function() |
92 | -- print(batch_send_log) | ||
67 | l:send( "key", table_unpack( batch_values)) | 93 | l:send( "key", table_unpack( batch_values)) |
68 | end | 94 | end |
69 | if loop > preloop then | 95 | if loop > preloop then |
@@ -76,57 +102,35 @@ local function ziva( preloop, loop, batch) | |||
76 | return lanes.now_secs() - t1 | 102 | return lanes.now_secs() - t1 |
77 | end | 103 | end |
78 | 104 | ||
105 | --################################################################################################## | ||
106 | |||
107 | TEST1 = TEST1 or 1000 | ||
108 | PREFILL1 = PREFILL1 or 10000 | ||
109 | FILL1 = FILL1 or 2000000 | ||
110 | |||
79 | local tests1 = | 111 | local tests1 = |
80 | { | 112 | { |
81 | { 10000, 2000000, 0}, | 113 | { PREFILL1, FILL1, 0}, |
82 | { 10000, 2000000, 1}, | 114 | { PREFILL1, FILL1, 1}, |
83 | { 10000, 2000000, 2}, | 115 | { PREFILL1, FILL1, 2}, |
84 | { 10000, 2000000, 3}, | 116 | { PREFILL1, FILL1, 3}, |
85 | { 10000, 2000000, 5}, | 117 | { PREFILL1, FILL1, 5}, |
86 | { 10000, 2000000, 8}, | 118 | { PREFILL1, FILL1, 8}, |
87 | { 10000, 2000000, 13}, | 119 | { PREFILL1, FILL1, 13}, |
88 | { 10000, 2000000, 21}, | 120 | { PREFILL1, FILL1, 21}, |
89 | { 10000, 2000000, 44}, | 121 | { PREFILL1, FILL1, 44}, |
122 | { PREFILL1, FILL1, 65}, | ||
90 | } | 123 | } |
91 | print "############################################\ntests #1" | 124 | print "############################################ tests #1" |
92 | for k, v in pairs( tests1) do | 125 | for i, v in ipairs( tests1) do |
126 | if i > TEST1 then break end | ||
93 | local pre, loop, batch = v[1], v[2], v[3] | 127 | local pre, loop, batch = v[1], v[2], v[3] |
94 | print( "testing", pre, loop, batch) | 128 | print("-------------------------------------------------\n") |
95 | print( pre, loop, batch, "duration = " .. ziva( pre, loop, batch) .. "\n") | 129 | print("START", "prefill="..pre, "fill="..loop, "batch="..batch) |
130 | print("DURATION = " .. ziva( pre, loop, batch) .. "\n") | ||
96 | end | 131 | end |
97 | 132 | ||
98 | --[[ | 133 | --################################################################################################## |
99 | V 2.1.0: | ||
100 | ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s | ||
101 | ziva( 30000, 0) -> 8s ziva( 20000, 30000) -> 7s | ||
102 | ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s | ||
103 | ziva( 50000, 0) -> 24s ziva( 40000, 50000) -> 23s | ||
104 | ziva( 60000, 0) -> 34s ziva( 50000, 60000) -> 33s | ||
105 | |||
106 | SIMPLIFIED: | ||
107 | ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s | ||
108 | ziva( 30000, 0) -> 9s ziva( 20000, 30000) -> 8s | ||
109 | ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s | ||
110 | ziva( 50000, 0) -> 25s ziva( 40000, 50000) -> 24s | ||
111 | ziva( 60000, 0) -> 35s ziva( 50000, 60000) -> 35s | ||
112 | |||
113 | FIFO: | ||
114 | ziva( 2000000, 0) -> 9s ziva( 1000000, 2000000) -> 33s | ||
115 | ziva( 3000000, 0) -> 14s ziva( 2000000, 3000000) -> 40s | ||
116 | ziva( 4000000, 0) -> 20s ziva( 3000000, 4000000) -> 27s | ||
117 | ziva( 5000000, 0) -> 24s ziva( 4000000, 5000000) -> 42s | ||
118 | ziva( 6000000, 0) -> 29s ziva( 5000000, 6000000) -> 55s | ||
119 | |||
120 | FIFO BATCHED: | ||
121 | ziva( 4000000, 0, 1) -> 20s | ||
122 | ziva( 4000000, 0, 2) -> 11s | ||
123 | ziva( 4000000, 0, 3) -> 7s | ||
124 | ziva( 4000000, 0, 5) -> 5s | ||
125 | ziva( 4000000, 0, 8) -> 3s | ||
126 | ziva( 4000000, 0, 13) -> 3s | ||
127 | ziva( 4000000, 0, 21) -> 3s | ||
128 | ziva( 4000000, 0, 44) -> 2s | ||
129 | ]] | ||
130 | 134 | ||
131 | -- sequential write/read (no parallelization involved) | 135 | -- sequential write/read (no parallelization involved) |
132 | local function ziva2( preloop, loop, batch) | 136 | local function ziva2( preloop, loop, batch) |
@@ -159,7 +163,7 @@ local function ziva2( preloop, loop, batch) | |||
159 | for i = 1, preloop, step do | 163 | for i = 1, preloop, step do |
160 | batch_send() | 164 | batch_send() |
161 | end | 165 | end |
162 | print( "stored " .. (l:count( "key") or 0) .. " items in the linda before starting consumer lane") | 166 | print( "stored " .. (l:count( "key") or 0) .. " items in the linda before starting the alternating reads and writes") |
163 | -- loop that alternatively sends and reads data off the linda | 167 | -- loop that alternatively sends and reads data off the linda |
164 | if loop > preloop then | 168 | if loop > preloop then |
165 | for i = preloop + 1, loop, step do | 169 | for i = preloop + 1, loop, step do |
@@ -169,40 +173,39 @@ local function ziva2( preloop, loop, batch) | |||
169 | end | 173 | end |
170 | -- here, we have preloop elements still waiting inside the linda | 174 | -- here, we have preloop elements still waiting inside the linda |
171 | for i = 1, preloop, step do | 175 | for i = 1, preloop, step do |
172 | batch_read() | 176 | batch_read() |
173 | end | 177 | end |
174 | return lanes.now_secs() - t1 | 178 | return lanes.now_secs() - t1 |
175 | end | 179 | end |
176 | 180 | ||
181 | --################################################################################################## | ||
182 | |||
183 | TEST2 = TEST2 or 1000 | ||
184 | PREFILL2 = PREFILL2 or 0 | ||
185 | FILL2 = FILL2 or 4000000 | ||
186 | |||
177 | local tests2 = | 187 | local tests2 = |
178 | { | 188 | { |
179 | -- prefill, then consume everything | 189 | { PREFILL2, FILL2}, |
180 | --[[ | 190 | { PREFILL2, FILL2, 1}, |
181 | { 4000000, 0}, | 191 | { PREFILL2, FILL2, 2}, |
182 | { 4000000, 0, 1}, | 192 | { PREFILL2, FILL2, 3}, |
183 | { 4000000, 0, 2}, | 193 | { PREFILL2, FILL2, 5}, |
184 | { 4000000, 0, 3}, | 194 | { PREFILL2, FILL2, 8}, |
185 | { 4000000, 0, 5}, | 195 | { PREFILL2, FILL2, 13}, |
186 | { 4000000, 0, 8}, | 196 | { PREFILL2, FILL2, 21}, |
187 | { 4000000, 0, 13}, | 197 | { PREFILL2, FILL2, 44}, |
188 | { 4000000, 0, 21}, | 198 | { PREFILL2, FILL2, 65}, |
189 | { 4000000, 0, 44}, | ||
190 | --]] | ||
191 | -- alternatively fill and consume | ||
192 | { 0, 4000000}, | ||
193 | { 0, 4000000, 1}, | ||
194 | { 0, 4000000, 2}, | ||
195 | { 0, 4000000, 3}, | ||
196 | { 0, 4000000, 5}, | ||
197 | { 0, 4000000, 8}, | ||
198 | { 0, 4000000, 13}, | ||
199 | { 0, 4000000, 21}, | ||
200 | { 0, 4000000, 44}, | ||
201 | } | 199 | } |
202 | 200 | ||
203 | print "\n############################################\ntests #2" | 201 | print "############################################ tests #2" |
204 | for k, v in pairs( tests2) do | 202 | for i, v in ipairs( tests2) do |
203 | if i > TEST2 then break end | ||
205 | local pre, loop, batch = v[1], v[2], v[3] | 204 | local pre, loop, batch = v[1], v[2], v[3] |
206 | print( "testing", pre, loop, batch) | 205 | print("-------------------------------------------------\n") |
207 | print( pre, loop, batch, "duration = " .. ziva2( pre, loop, batch) .. "\n") | 206 | print("START", "prefill="..pre, "fill="..loop, "batch="..(batch or "no")) |
207 | print("DURATION = " .. ziva2( pre, loop, batch) .. "\n") | ||
208 | end | 208 | end |
209 | |||
210 | print "############################################" | ||
211 | print "THE END" \ No newline at end of file | ||