Created
June 19, 2020 19:22
-
-
Save igormunkin/c941074fa9fdf0f7a4f068498fb5e24c to your computer and use it in GitHub Desktop.
GC pressure benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local G = 0 | |
function incG() G = G + 1 end | |
bench = { | |
start = function() | |
print(collectgarbage('count')) | |
collectgarbage('collect') | |
collectgarbage('stop') | |
return collectgarbage('count') | |
end, | |
stop = function() | |
local ret = collectgarbage('count') | |
collectgarbage('restart') | |
return ret | |
end, | |
} | |
box.cfg({ listen = 9998, wal_mode = 'none' }) | |
box.schema.user.grant('guest','execute','universe') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local nb = require('net.box') | |
local clock = require('clock') | |
local id, iterations = tonumber(arg[1]) or -1, tonumber(arg[2]) or 1e6 | |
print(("===== %s: #%d ====="):format(_TARANTOOL, id)) | |
local G = 0 | |
function incG() G = G + 1 end | |
box.cfg({ listen = 9999, log = 'tarantool.log', wal_mode = 'none' }) | |
box.schema.func.create('incG', { if_not_exists = true, language = 'LUA' }) | |
collectgarbage('collect') | |
collectgarbage('stop') | |
local before = collectgarbage('count') | |
local start = clock.time64() | |
for _ = 1, iterations do box.func.incG:call() end | |
local stop = clock.time64() | |
local after = collectgarbage('count') | |
assert(G == iterations) | |
print(('call by ref GC: %f Kb'):format(after - before)) | |
print(('call by ref time: %f sec'):format(tonumber(stop - start) / 1e9)) | |
collectgarbage('restart') | |
local connection = nb.connect('localhost:9998') | |
local before = connection:call('bench.start') | |
local start = clock.time64() | |
for _ = 1, iterations do connection:call('incG') end | |
local stop = clock.time64() | |
local after = connection:call('bench.stop') | |
print(('call GC: %f Kb'):format(after - before)) | |
local before = connection:call('bench.start') | |
local start = clock.time64() | |
for _ = 1, iterations do connection:eval('return incG()') end | |
local stop = clock.time64() | |
local after = connection:call('bench.stop') | |
print(('eval GC: %f Kb'):format(after - before)) | |
os.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment