Skip to content

Instantly share code, notes, and snippets.

@igormunkin
Created June 19, 2020 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igormunkin/c941074fa9fdf0f7a4f068498fb5e24c to your computer and use it in GitHub Desktop.
Save igormunkin/c941074fa9fdf0f7a4f068498fb5e24c to your computer and use it in GitHub Desktop.
GC pressure benchmark
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')
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