|
| 1 | +#!/usr/bin/env tarantool |
| 2 | + |
| 3 | +local tap = require('tap') |
| 4 | +local fio = require('fio') |
| 5 | +local popen = require('popen') |
| 6 | +package.cpath = './?.so;' .. package.cpath |
| 7 | +local memcached = require('memcached') |
| 8 | +local test = tap.test('memcached benchmarks') |
| 9 | +test:plan(3) |
| 10 | + |
| 11 | +local is_test_run = os.getenv('LISTEN') |
| 12 | + |
| 13 | +if type(box.cfg) == 'function' then |
| 14 | + box.cfg{ |
| 15 | + wal_mode = 'none', |
| 16 | + memtx_memory = 100 * 1024 * 1024, |
| 17 | + } |
| 18 | + box.schema.user.grant('guest', 'read,write,execute', 'universe') |
| 19 | +end |
| 20 | + |
| 21 | +local port = 11211 |
| 22 | +local mc = memcached.create('memcached', tostring(port), {}) |
| 23 | + |
| 24 | +local function run_memtier(instance, memtier_path, proto) |
| 25 | + instance:cfg({ |
| 26 | + protocol = proto, |
| 27 | + }) |
| 28 | + local memtier_proto = 'memcache_' .. proto |
| 29 | + local memtier_argv = { |
| 30 | + memtier_path, |
| 31 | + '--server=127.0.0.1', |
| 32 | + string.format('--port=%d', port), |
| 33 | + string.format('--protocol=%s', memtier_proto), |
| 34 | + '--threads=10', |
| 35 | + '--test-time=2', |
| 36 | + '--hide-histogram' |
| 37 | + } |
| 38 | + |
| 39 | + local stdout = is_test_run and popen.opts.PIPE or popen.opts.INHERIT |
| 40 | + local stderr = is_test_run and popen.opts.PIPE or popen.opts.INHERIT |
| 41 | + local ph = popen.new(memtier_argv, { |
| 42 | + stdout = stdout, |
| 43 | + stderr = stderr, |
| 44 | + }) |
| 45 | + local res = ph:wait() |
| 46 | + ph:close() |
| 47 | + |
| 48 | + return res.exit_code |
| 49 | +end |
| 50 | + |
| 51 | +-- path to memtier_benchmark in case of tarantool that run in project root dir |
| 52 | +local memtier_path = 'test/bench/memtier_benchmark' |
| 53 | +if not fio.path.exists(memtier_path) then |
| 54 | + -- path to memtier_benchmark in case of test-run |
| 55 | + memtier_path = './memtier_benchmark' |
| 56 | +end |
| 57 | + |
| 58 | +test:is(fio.path.exists(memtier_path), true, 'memtier_benchmark binary is available') |
| 59 | +test:is(run_memtier(mc, memtier_path, 'text'), 0, 'memtier with text protocol') |
| 60 | +test:is(run_memtier(mc, memtier_path, 'binary'), 0, 'memtier with binary protocol') |
| 61 | + |
| 62 | +os.exit(0) |
0 commit comments