Skip to content

Instantly share code, notes, and snippets.

@igormunkin
Last active October 5, 2021 12:34
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/e956396d8fb3348d3ebbad60588af297 to your computer and use it in GitHub Desktop.
Save igormunkin/e956396d8fb3348d3ebbad60588af297 to your computer and use it in GitHub Desktop.
#!/usr/bin/tarantool
-- vim:ts=4 ss=4 sw=4 expandtab
-- Usage: tarantool relay-1mops.lua [num_ops] [nodes]
-- num_ops should be a number multiple of num_fibers * ops_per_txn
-- nodes should be a number from 1 to 31
local clock = require('clock')
local fiber = require('fiber')
local popen = require('popen')
local yaml = require('yaml')
-- TUNE OPTIONS HERE
-- working dir is cleared/created for every run, set mwd
-- during the test a subdir will be created for each replica
local mwd = './relay-test.data'
-- turn true to test the qsync
local test_qsync = false
-- number of operations performed by test
local num_ops = tonumber(arg[1] or 1e6)
-- number of fibers
local num_fibers = 50
-- number of operations per transaction
local ops_per_txn = 100
-- check the number of operations value
local txns, tail = math.modf(num_ops / num_fibers / ops_per_txn)
assert(txns > 0 and tail == 0,
('Invalid number of iterations: %s'):format(num_ops))
-- number of nodes - master and replicas
local nodes, tail = math.modf(tonumber(arg[2] or 0) + 1)
assert(nodes > 0 and nodes < 32 and tail == 0,
('Invalid number of nodes: %s'):format(nodes))
-- posterior evaluation shows that 256Mb is enough to make
-- 4 million replaces
local default_memtx_memory = 256 * 1024 * 1024
local memtx_memory = math.max(math.ceil(num_ops / 1e6 * default_memtx_memory),
default_memtx_memory)
-- END OF TUNABLE OPTIONS
print(('making %d operations, %d operations per txn using %d fibers'):format(
num_ops, ops_per_txn, num_fibers))
--- transactions per fiber
local trans_per_fiber = num_ops/ops_per_txn/num_fibers
os.execute(('rm -rf %s'):format(mwd))
os.execute(('mkdir -p %s'):format(mwd))
box.cfg({
listen = 3301,
log_level = 0,
memtx_memory = memtx_memory,
read_only = false,
replication = 'replicator:password@localhost:3301',
work_dir = mwd,
})
if test_qsync then
box.cfg({ replication_synchro_quorum = nodes })
end
box.schema.user.create('replicator', { password = 'password' })
box.schema.user.grant('replicator', 'replication')
-- number of nodes, storage for popen handles
local nodes_ph = {}
-- run replicas (if needed)
if nodes > 1 then
print(('starting %d replicas'):format(nodes - 1))
for i = 2, nodes do
-- subdir for replica's data
local rwd = ('relay-test.replica-%s'):format(i)
os.execute(('rm -rf %s'):format(rwd))
os.execute(('mkdir -p %s'):format(rwd))
-- command line for replica to start
local cmd = { arg[-1], '-e', ([[
box.cfg({
listen = %d,
log_level = 0,
memtx_memory = %d,
read_only = false,
replication = 'replicator:password@localhost:3301',
work_dir = '%s',
})
]]):format(3300 + i, memtx_memory, rwd) }
local res, err = popen.new(cmd, {
stdin = 'devnull',
stdout = 'devnull',
stderr = 'devnull',
})
assert(res, ('Error running replica %d: %s'):format(i, err))
nodes_ph[i] = res
end
-- wait for all replicas to connect
while #box.info.replication < nodes do
fiber.sleep(0.1)
end
end
local space = box.schema.create_space('test',
test_qsync and { is_sync = true } or { })
space:create_index('pk', { type = 'HASH' })
-- each fiber runs the fiber_load that has evenly distributed workload
function fiber_load(start, s)
for i = 1, trans_per_fiber do
box.begin()
for j = 1, ops_per_txn do
s:replace{ start, start }
start = start + 1
end
box.commit()
end
end
-- fiber storage to join them
local fibers_storage = { }
-- start timer
local start = {
lsn = box.info.replication[1].lsn,
proc = clock.proc(),
time = clock.time(),
}
for i = 1, num_fibers do
fibers_storage[i] = fiber.create(fiber_load, i*num_ops, space)
fibers_storage[i]:wakeup() -- needed for backward compatibility with 1.7
end
-- wait for all fibers to finish
for i = 1, num_fibers do
while fibers_storage[i]:status() ~= 'dead' do
fiber.yield()
end -- the loop is needed for backward compatibility with 1.7
end
local ops_done = box.info.replication[1].lsn
-- stop timer for master
local stop = {
lsn = ops_done - start.lsn,
proc = clock.proc() - start.proc,
time = clock.time() - start.time,
}
assert(num_ops == stop.lsn,
('Missing data: %d/%d inserted'):format(stop.lsn, num_ops))
print(('master done in time: %f, cpu: %f\nmaster speed: %d ops/sec'):format(
stop.time, stop.proc, math.floor(stop.lsn / stop.time)))
-- wait for all replicas and kill them
if nodes > 1 then
local done = false
repeat
for i = 2, nodes do
local r_vclock = box.info.replication[i].downstream.vclock
if r_vclock and r_vclock[1] < ops_done then
done = false
break
end
done = true
end
if not done then
fiber.sleep(0.001)
end
until done
-- stop timer for replicas
stop = {
lsn = box.info.replication[nodes].downstream.vclock[1] - start.lsn,
time = clock.time() - start.time,
proc = clock.proc() - start.proc,
}
print(('replicas done in time: %f, cpu: %f\nreplicas speed: %f ops/sec'):format(
stop.time, stop.proc, math.floor(stop.lsn / stop.time)))
for _, replica in pairs(nodes_ph) do
replica:kill()
replica:wait()
end
end
os.exit(0)
@igormunkin
Copy link
Author

Some stats for wall clock timings and operations per second (Apple M1 vs Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz).

1000000 replaces
Apple M1 (wall clock) Apple M1 (ops/sec) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (wall clock) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (ops/sec) Relation (i5-1038NG7/M1)
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Run 1 0.513485 1947476 1.078086 927569 2.099547212
Run 2 0.515587 1939536 1.11699 895263 2.166443297
Run 3 0.514109 1945113 1.094748 913452 2.129408355
Run 4 0.520584 1920919 1.090597 916929 2.094949134
Run 5 0.518380 1929087 1.11464 897150 2.150237278
Run 6 0.537575 1860205 1.095783 912589 2.038381621
Run 7 0.530633 1884541 1.079496 926358 2.034355195
Run 8 0.533390 1874800 1.0789 926869 2.022722586
Run 9 0.516247 1937057 1.110369 900601 2.150848334
Run 10 0.515243 1940832 1.081358 924763 2.098733995
Run 11 0.517204 1933472 1.066245 937870 2.061555982
Run 12 0.522334 1914484 1.089303 918018 2.085452986
Run 13 0.515059 1941525 1.058271 944937 2.054659757
Run 14 0.530446 1885205 1.072334 932545 2.021570527
Run 15 0.523705 1909471 1.075167 930088 2.053001213
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Med 0.518380 1929087 1.081358 924763 2.086033412
Avg 0.521599 1917581.533 1.086819133 920333.4 2.083630699
Min 0.513485 1860205 1.058271 895263 2.060957964
Max 0.537575 1947476 1.11699 944937 2.077831
5000000 replaces
Apple M1 (wall clock) Apple M1 (ops/sec) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (wall clock) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (ops/sec) Relation (i5-1038NG7/M1)
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Run 1 2.583679 1935224 5.365338 931907 2.076627166
Run 2 2.565490 1948945 5.426003 921488 2.114996745
Run 3 2.577809 1939631 5.464272 915034 2.119735015
Run 4 2.578820 1938871 5.29165 944884 2.051965628
Run 5 2.596891 1925379 5.434663 920020 2.092757455
Run 6 2.612779 1913671 5.417282 922972 2.073379341
Run 7 2.583271 1935530 5.480857 912266 2.121673258
Run 8 2.589305 1931020 5.324999 938967 2.05653602
Run 9 2.581282 1937022 5.300625 943285 2.053485439
Run 10 2.583490 1935366 5.247602 952816 2.031206624
Run 11 2.577924 1939545 5.163495 968336 2.00296634
Run 12 2.597693 1924784 5.213042 959132 2.0067968
Run 13 2.583340 1935478 5.283318 946374 2.045150077
Run 14 2.570901 1944843 5.43772 919503 2.115102837
Run 15 2.567064 1947750 5.381596 929092 2.09640118
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Med 2.583271 1935530 5.365338 931907 2.076955147
Avg 2.583315867 1935537.267 5.3488308 935071.7333 2.070529148
Min 2.56549 1913671 5.163495 912266 2.012673992
Max 2.612779 1948945 5.480857 968336 2.09771167
10000000 replaces
Apple M1 (wall clock) Apple M1 (ops/sec) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (wall clock) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (ops/sec) Relation (i5-1038NG7/M1)
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Run 1 5.160520 1937789 10.798749 926033 2.092569935
Run 2 5.162725 1936961 10.828895 923455 2.097515363
Run 3 5.325083 1877905 10.714711 933296 2.012120938
Run 4 5.163672 1936606 10.839264 922571 2.099138752
Run 5 5.223807 1914312 10.696577 934878 2.047659303
Run 6 5.188444 1927360 10.73609 931437 2.069231161
Run 7 5.141926 1944796 10.710851 933632 2.083042619
Run 8 5.146730 1942981 10.674525 936809 2.074040216
Run 9 5.175809 1932065 10.605407 942915 2.049033687
Run 10 5.207238 1920403 10.738789 931203 2.062281194
Run 11 5.153160 1940556 10.680092 936321 2.072532582
Run 12 5.167791 1935062 10.522609 950334 2.036190899
Run 13 5.160697 1937722 10.612297 942303 2.056368936
Run 14 5.155869 1939537 10.664438 937695 2.068407479
Run 15 5.233821 1910649 10.863212 920538 2.075579581
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Med 5.163672 1936606 10.710851 933632 2.074270209
Avg 5.184486133 1928980.267 10.71243373 933561.3333 2.066247928
Min 5.141926 1877905 10.522609 920538 2.046433379
Max 5.325083 1944796 10.863212 950334 2.040008015
15000000 replaces
Apple M1 (wall clock) Apple M1 (ops/sec) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (wall clock) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (ops/sec) Relation (i5-1038NG7/M1)
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Run 1 7.683132 1952328 15.920179 942200 2.072094948
Run 2 7.719851 1943042 16.268209 922043 2.107321631
Run 3 7.717612 1943606 16.28582 921046 2.110214921
Run 4 7.761347 1932654 15.94528 940717 2.054447508
Run 5 7.695678 1949146 16.083569 932628 2.08994828
Run 6 7.711488 1945149 15.858925 945839 2.05653241
Run 7 7.698423 1948451 15.905716 943057 2.066100551
Run 8 7.707843 1946069 15.710405 954781 2.038236248
Run 9 7.708424 1945923 16.04504 934868 2.08149422
Run 10 7.720346 1942918 16.076839 933019 2.082398768
Run 11 7.694705 1949392 15.881122 944517 2.063902645
Run 12 7.725098 1941722 16.508107 908644 2.13694467
Run 13 7.684736 1951921 16.49312 909470 2.146218165
Run 14 7.706184 1946488 16.134264 929698 2.093677493
Run 15 7.735034 1939228 16.02429 936078 2.071650881
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Med 7.708424 1945923 16.04504 934868 2.08149422
Avg 7.711326733 1945202.467 16.076059 933240.3333 2.084733219
Min 7.683132 1932654 15.710405 908644 2.044791759
Max 7.761347 1952328 16.508107 954781 2.126964173
20000000 replaces
Apple M1 (wall clock) Apple M1 (ops/sec) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (wall clock) Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (ops/sec) Relation (i5-1038NG7/M1)
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Run 1 10.454208 1913105 21.257546 940842 2.033396121
Run 2 10.543672 1896872 21.468545 931595 2.036154482
Run 3 10.456510 1912684 21.37936 935481 2.044598054
Run 4 10.337435 1934715 21.822884 916469 2.111054048
Run 5 10.367294 1929143 21.661464 923298 2.08940385
Run 6 10.340018 1934232 21.758416 919184 2.104291888
Run 7 10.340294 1934180 21.383367 935306 2.067965089
Run 8 10.401648 1922772 21.398162 934659 2.057189591
Run 9 10.364378 1929686 21.324088 937906 2.057440205
Run 10 10.363388 1929870 21.490854 930628 2.073728591
Run 11 10.325387 1936973 21.664436 923171 2.098171817
Run 12 10.351826 1932026 21.447941 932490 2.071899296
Run 13 10.452252 1913463 21.521186 929316 2.058999917
Run 14 10.388245 1925252 21.445809 932583 2.064430421
Run 15 10.387833 1925329 21.638631 924272 2.083074593
-------- ----------------------- -------------------- --------------------------------------------------------- ------------------------------------------------------ --------------------------
Med 10.367294 1929143 21.468545 931595 2.070795426
Avg 10.39162587 1924686.8 21.51084593 929813.3333 2.070017359
Min 10.325387 1896872 21.257546 916469 2.058765061
Max 10.543672 1936973 21.822884 940842 2.069761275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment