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