diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-05 08:49:48 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-05 08:51:09 +0200 |
| commit | c64f9dcd61c1ad7bef3dbf5b7647a2a2da23ac0f (patch) | |
| tree | 349aa02b2367d11d252468af983d719f20a00a42 /tests | |
| parent | 2cb54d2ac028d648deab6d49a051f53a0bb67fb2 (diff) | |
| download | lanes-c64f9dcd61c1ad7bef3dbf5b7647a2a2da23ac0f.tar.gz lanes-c64f9dcd61c1ad7bef3dbf5b7647a2a2da23ac0f.tar.bz2 lanes-c64f9dcd61c1ad7bef3dbf5b7647a2a2da23ac0f.zip | |
Enable manual control of GC inside keeper states
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/keeper.lua | 15 | ||||
| -rw-r--r-- | tests/linda_perf.lua | 64 |
2 files changed, 31 insertions, 48 deletions
diff --git a/tests/keeper.lua b/tests/keeper.lua index 9b38f02..6dbbd15 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | -- Test program for Lua Lanes | 4 | -- Test program for Lua Lanes |
| 5 | -- | 5 | -- |
| 6 | 6 | ||
| 7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} | 7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 1, keepers_gc_threshold = 500} |
| 8 | 8 | ||
| 9 | do | 9 | do |
| 10 | print "Linda names test:" | 10 | print "Linda names test:" |
| @@ -12,7 +12,20 @@ do | |||
| 12 | local unnamedLinda2 = lanes.linda("") | 12 | local unnamedLinda2 = lanes.linda("") |
| 13 | local veeeerrrryyyylooongNamedLinda= lanes.linda( "veeeerrrryyyylooongNamedLinda", 1) | 13 | local veeeerrrryyyylooongNamedLinda= lanes.linda( "veeeerrrryyyylooongNamedLinda", 1) |
| 14 | print(unnamedLinda, unnamedLinda2, veeeerrrryyyylooongNamedLinda) | 14 | print(unnamedLinda, unnamedLinda2, veeeerrrryyyylooongNamedLinda) |
| 15 | print "GC deadlock test start" | ||
| 16 | -- store a linda in another linda (-> in a keeper) | ||
| 17 | unnamedLinda:set("here", lanes.linda("temporary linda")) | ||
| 18 | -- repeatedly add and remove stuff in the linda so that a GC happens during the keeper operation | ||
| 19 | for i = 1, 1000 do | ||
| 20 | for j = 1, 1000 do -- send 1000 tables | ||
| 21 | unnamedLinda:send("here", {"a", "table", "with", "some", "stuff"}) | ||
| 22 | end | ||
| 23 | unnamedLinda:set("here") -- clear everything | ||
| 24 | end | ||
| 15 | end | 25 | end |
| 26 | print "collecting garbage" | ||
| 27 | collectgarbage() | ||
| 28 | print "GC deadlock test done" | ||
| 16 | 29 | ||
| 17 | local print_id = 0 | 30 | local print_id = 0 |
| 18 | local PRINT = function(...) | 31 | local PRINT = function(...) |
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 9177852..c736428 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua | |||
| @@ -1,5 +1,5 @@ | |||
| 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=20000 } |
| 3 | 3 | ||
| 4 | -- set TEST1, PREFILL1, FILL1, TEST2, PREFILL2, FILL2 from the command line | 4 | -- set TEST1, PREFILL1, FILL1, TEST2, PREFILL2, FILL2 from the command line |
| 5 | 5 | ||
| @@ -17,6 +17,8 @@ local finalizer = function(err, stk) | |||
| 17 | end | 17 | end |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | --################################################################################################## | ||
| 21 | |||
| 20 | -- this lane eats items in the linda one by one | 22 | -- this lane eats items in the linda one by one |
| 21 | local eater = function( l, loop) | 23 | local eater = function( l, loop) |
| 22 | set_finalizer(finalizer) | 24 | set_finalizer(finalizer) |
| @@ -32,6 +34,8 @@ local eater = function( l, loop) | |||
| 32 | print("eater: done ("..val..")") | 34 | print("eater: done ("..val..")") |
| 33 | end | 35 | end |
| 34 | 36 | ||
| 37 | --################################################################################################## | ||
| 38 | |||
| 35 | -- this lane eats items in the linda in batches | 39 | -- this lane eats items in the linda in batches |
| 36 | local gobbler = function( l, loop, batch) | 40 | local gobbler = function( l, loop, batch) |
| 37 | set_finalizer(finalizer) | 41 | set_finalizer(finalizer) |
| @@ -47,9 +51,13 @@ local gobbler = function( l, loop, batch) | |||
| 47 | print("gobbler: done ("..val..")") | 51 | print("gobbler: done ("..val..")") |
| 48 | end | 52 | end |
| 49 | 53 | ||
| 54 | --################################################################################################## | ||
| 55 | |||
| 50 | local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) | 56 | local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) |
| 51 | local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) | 57 | local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) |
| 52 | 58 | ||
| 59 | --################################################################################################## | ||
| 60 | |||
| 53 | -- main thread writes data while a lane reads it | 61 | -- main thread writes data while a lane reads it |
| 54 | local function ziva( preloop, loop, batch) | 62 | local function ziva( preloop, loop, batch) |
| 55 | -- prefill the linda a bit to increase fifo stress | 63 | -- prefill the linda a bit to increase fifo stress |
| @@ -94,6 +102,8 @@ local function ziva( preloop, loop, batch) | |||
| 94 | return lanes.now_secs() - t1 | 102 | return lanes.now_secs() - t1 |
| 95 | end | 103 | end |
| 96 | 104 | ||
| 105 | --################################################################################################## | ||
| 106 | |||
| 97 | TEST1 = TEST1 or 1000 | 107 | TEST1 = TEST1 or 1000 |
| 98 | PREFILL1 = PREFILL1 or 10000 | 108 | PREFILL1 = PREFILL1 or 10000 |
| 99 | FILL1 = FILL1 or 2000000 | 109 | FILL1 = FILL1 or 2000000 |
| @@ -109,6 +119,7 @@ local tests1 = | |||
| 109 | { PREFILL1, FILL1, 13}, | 119 | { PREFILL1, FILL1, 13}, |
| 110 | { PREFILL1, FILL1, 21}, | 120 | { PREFILL1, FILL1, 21}, |
| 111 | { PREFILL1, FILL1, 44}, | 121 | { PREFILL1, FILL1, 44}, |
| 122 | { PREFILL1, FILL1, 65}, | ||
| 112 | } | 123 | } |
| 113 | print "############################################ tests #1" | 124 | print "############################################ tests #1" |
| 114 | for i, v in ipairs( tests1) do | 125 | for i, v in ipairs( tests1) do |
| @@ -119,38 +130,7 @@ for i, v in ipairs( tests1) do | |||
| 119 | print("DURATION = " .. ziva( pre, loop, batch) .. "\n") | 130 | print("DURATION = " .. ziva( pre, loop, batch) .. "\n") |
| 120 | end | 131 | end |
| 121 | 132 | ||
| 122 | --[[ | 133 | --################################################################################################## |
| 123 | V 2.1.0: | ||
| 124 | ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s | ||
| 125 | ziva( 30000, 0) -> 8s ziva( 20000, 30000) -> 7s | ||
| 126 | ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s | ||
| 127 | ziva( 50000, 0) -> 24s ziva( 40000, 50000) -> 23s | ||
| 128 | ziva( 60000, 0) -> 34s ziva( 50000, 60000) -> 33s | ||
| 129 | |||
| 130 | SIMPLIFIED: | ||
| 131 | ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s | ||
| 132 | ziva( 30000, 0) -> 9s ziva( 20000, 30000) -> 8s | ||
| 133 | ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s | ||
| 134 | ziva( 50000, 0) -> 25s ziva( 40000, 50000) -> 24s | ||
| 135 | ziva( 60000, 0) -> 35s ziva( 50000, 60000) -> 35s | ||
| 136 | |||
| 137 | FIFO: | ||
| 138 | ziva( 2000000, 0) -> 9s ziva( 1000000, 2000000) -> 33s | ||
| 139 | ziva( 3000000, 0) -> 14s ziva( 2000000, 3000000) -> 40s | ||
| 140 | ziva( 4000000, 0) -> 20s ziva( 3000000, 4000000) -> 27s | ||
| 141 | ziva( 5000000, 0) -> 24s ziva( 4000000, 5000000) -> 42s | ||
| 142 | ziva( 6000000, 0) -> 29s ziva( 5000000, 6000000) -> 55s | ||
| 143 | |||
| 144 | FIFO BATCHED: | ||
| 145 | ziva( 4000000, 0, 1) -> 20s | ||
| 146 | ziva( 4000000, 0, 2) -> 11s | ||
| 147 | ziva( 4000000, 0, 3) -> 7s | ||
| 148 | ziva( 4000000, 0, 5) -> 5s | ||
| 149 | ziva( 4000000, 0, 8) -> 3s | ||
| 150 | ziva( 4000000, 0, 13) -> 3s | ||
| 151 | ziva( 4000000, 0, 21) -> 3s | ||
| 152 | ziva( 4000000, 0, 44) -> 2s | ||
| 153 | ]] | ||
| 154 | 134 | ||
| 155 | -- sequential write/read (no parallelization involved) | 135 | -- sequential write/read (no parallelization involved) |
| 156 | local function ziva2( preloop, loop, batch) | 136 | local function ziva2( preloop, loop, batch) |
| @@ -183,7 +163,7 @@ local function ziva2( preloop, loop, batch) | |||
| 183 | for i = 1, preloop, step do | 163 | for i = 1, preloop, step do |
| 184 | batch_send() | 164 | batch_send() |
| 185 | end | 165 | end |
| 186 | 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") |
| 187 | -- loop that alternatively sends and reads data off the linda | 167 | -- loop that alternatively sends and reads data off the linda |
| 188 | if loop > preloop then | 168 | if loop > preloop then |
| 189 | for i = preloop + 1, loop, step do | 169 | for i = preloop + 1, loop, step do |
| @@ -198,25 +178,14 @@ local function ziva2( preloop, loop, batch) | |||
| 198 | return lanes.now_secs() - t1 | 178 | return lanes.now_secs() - t1 |
| 199 | end | 179 | end |
| 200 | 180 | ||
| 181 | --################################################################################################## | ||
| 182 | |||
| 201 | TEST2 = TEST2 or 1000 | 183 | TEST2 = TEST2 or 1000 |
| 202 | PREFILL2 = PREFILL2 or 0 | 184 | PREFILL2 = PREFILL2 or 0 |
| 203 | FILL2 = FILL2 or 4000000 | 185 | FILL2 = FILL2 or 4000000 |
| 204 | 186 | ||
| 205 | local tests2 = | 187 | local tests2 = |
| 206 | { | 188 | { |
| 207 | -- prefill, then consume everything | ||
| 208 | --[[ | ||
| 209 | { 4000000, 0}, | ||
| 210 | { 4000000, 0, 1}, | ||
| 211 | { 4000000, 0, 2}, | ||
| 212 | { 4000000, 0, 3}, | ||
| 213 | { 4000000, 0, 5}, | ||
| 214 | { 4000000, 0, 8}, | ||
| 215 | { 4000000, 0, 13}, | ||
| 216 | { 4000000, 0, 21}, | ||
| 217 | { 4000000, 0, 44}, | ||
| 218 | --]] | ||
| 219 | -- alternatively fill and consume | ||
| 220 | { PREFILL2, FILL2}, | 189 | { PREFILL2, FILL2}, |
| 221 | { PREFILL2, FILL2, 1}, | 190 | { PREFILL2, FILL2, 1}, |
| 222 | { PREFILL2, FILL2, 2}, | 191 | { PREFILL2, FILL2, 2}, |
| @@ -226,6 +195,7 @@ local tests2 = | |||
| 226 | { PREFILL2, FILL2, 13}, | 195 | { PREFILL2, FILL2, 13}, |
| 227 | { PREFILL2, FILL2, 21}, | 196 | { PREFILL2, FILL2, 21}, |
| 228 | { PREFILL2, FILL2, 44}, | 197 | { PREFILL2, FILL2, 44}, |
| 198 | { PREFILL2, FILL2, 65}, | ||
| 229 | } | 199 | } |
| 230 | 200 | ||
| 231 | print "############################################ tests #2" | 201 | print "############################################ tests #2" |
