Skip to content

Commit e3cac2f

Browse files
committed
Enable arbitrary commands to be run on cluster mode
1 parent 18d2646 commit e3cac2f

9 files changed

+231
-50
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,56 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- name: Install dependencies
1414
run: |
15-
sudo apt-get -qq update
15+
sudo apt-get -qq update
1616
sudo apt-get install autoconf automake pkg-config libevent-dev libpcre3-dev libssl-dev
1717
- name: Build
18-
run: autoreconf -ivf && ./configure && make
18+
run: autoreconf -ivf && ./configure && make -j
1919
- name: Setup Python
20-
uses: actions/setup-python@v1
20+
uses: actions/setup-python@v2
2121
with:
2222
python-version: '3.6'
23+
architecture: x64
2324

24-
- name: Cache pip
25-
uses: actions/cache@v1
26-
with:
27-
path: ~/.cache/pip # This path is specific to Ubuntu
28-
# Look to see if there is a cache hit for the corresponding requirements file
29-
key: ${{ runner.os }}-pip-${{ hashFiles('tests/test_requirements.txt') }}
30-
restore-keys: |
31-
${{ runner.os }}-pip-
32-
${{ runner.os }}-
3325
- name: Install Python dependencies
34-
run: pip install -r tests/test_requirements.txt
26+
run: pip install -r ./tests/test_requirements.txt
3527

3628
- name: Cache Redis
3729
id: cache-redis
3830
uses: actions/cache@v1
3931
with:
40-
path: /home/runner/work/memtier_benchmark/memtier_benchmark/redis
32+
path: /home/runner/work/redis
4133
key: ${{ runner.os }}-redis
4234

4335
- name: Install Redis Server test dependencies
4436
if: steps.cache-redis.outputs.cache-hit != 'true'
4537
run: |
46-
git clone git://github.com/antirez/redis.git --branch unstable
38+
git clone git://github.com/antirez/redis.git --branch 6.2.2
4739
cd redis
48-
make BUILD_TLS=yes
40+
make BUILD_TLS=yes -j
4941
./utils/gen-test-certs.sh
5042
./src/redis-server --version
5143
cd ..
5244
5345
- name: Test OSS TCP
46+
timeout-minutes: 10
5447
run: |
5548
cd tests
5649
MEMTIER_BINARY=./../memtier_benchmark \
57-
python3 -m RLTest \
50+
RLTest \
5851
--env oss -v --clear-logs \
5952
--oss-redis-path ../redis/src/redis-server
6053
cd ..
6154
6255
- name: Test OSS TCP TLS
6356
if: matrix.platform == 'ubuntu-latest'
57+
timeout-minutes: 10
6458
run: |
6559
cd tests
6660
TLS_CERT=../redis/tests/tls/redis.crt \
6761
TLS_KEY=../redis/tests/tls/redis.key \
6862
TLS_CACERT=../redis/tests/tls/ca.crt \
6963
MEMTIER_BINARY=../memtier_benchmark \
70-
python3 -m RLTest \
64+
RLTest \
7165
--env oss -v --clear-logs \
7266
--oss-redis-path ../redis/src/redis-server \
7367
--tls-cert-file ../redis/tests/tls/redis.crt \
@@ -77,23 +71,25 @@ jobs:
7771
cd ..
7872
7973
- name: Test OSS-CLUSTER TCP
74+
timeout-minutes: 10
8075
run: |
8176
cd tests
8277
MEMTIER_BINARY=./../memtier_benchmark \
83-
python3 -m RLTest \
78+
RLTest \
8479
--env oss-cluster -v --clear-logs --shards-count 3 \
8580
--oss-redis-path ../redis/src/redis-server
8681
cd ..
8782
8883
- name: Test OSS-CLUSTER TCP TLS
84+
timeout-minutes: 10
8985
if: matrix.platform == 'ubuntu-latest'
9086
run: |
9187
cd tests
9288
TLS_CERT=../redis/tests/tls/redis.crt \
9389
TLS_KEY=../redis/tests/tls/redis.key \
9490
TLS_CACERT=../redis/tests/tls/ca.crt \
9591
MEMTIER_BINARY=../memtier_benchmark \
96-
python3 -m RLTest \
92+
RLTest \
9793
--env oss-cluster --shards-count 3 -v --clear-logs \
9894
--oss-redis-path ../redis/src/redis-server \
9995
--tls-cert-file ../redis/tests/tls/redis.crt \

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ stamp-h1
2828
# memtier outputs
2929
*.hgrm
3030
*.txt
31+
!/tests/test_requirements.txt
3132
__pycache__

cluster_client.cpp

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,54 @@ bool cluster_client::get_key_for_conn(unsigned int conn_id, int iter, unsigned l
358358
}
359359
}
360360

361+
362+
void cluster_client::create_arbitrary_request(const arbitrary_command* cmd, struct timeval& timestamp, unsigned int conn_id) {
363+
int cmd_size = 0;
364+
365+
benchmark_debug_log("%s [%s]:\n", cmd->command_name.c_str(), cmd->command.c_str());
366+
367+
for (unsigned int i = 0; i < cmd->command_args.size(); i++) {
368+
const command_arg* arg = &cmd->command_args[i];
369+
370+
if (arg->type == const_type) {
371+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg);
372+
} else if (arg->type == key_type) {
373+
unsigned long long key_index;
374+
375+
// get key
376+
if (!get_key_for_conn(conn_id, get_arbitrary_obj_iter_type(cmd, m_executed_command_index), &key_index)) {
377+
return;
378+
}
379+
380+
assert(key_index >= 0);
381+
assert(m_key_len > 0);
382+
383+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, m_key_buffer, m_key_len);
384+
} else if (arg->type == data_type) {
385+
unsigned int value_len;
386+
const char *value = m_obj_gen->get_value(0, &value_len);
387+
388+
assert(value != NULL);
389+
assert(value_len > 0);
390+
391+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, value, value_len);
392+
}
393+
}
394+
395+
m_connections[conn_id]->send_arbitrary_command_end(m_executed_command_index, &timestamp, cmd_size);
396+
}
397+
361398
// This function could use some urgent TLC -- but we need to do it without altering the behavior
362399
void cluster_client::create_request(struct timeval timestamp, unsigned int conn_id)
363400
{
401+
// are we using arbitrary command?
402+
if (m_config->arbitrary_commands->is_defined()) {
403+
const arbitrary_command* executed_command = m_config->arbitrary_commands->get_next_executed_command(m_arbitrary_command_ratio_count,
404+
m_executed_command_index);
405+
create_arbitrary_request(executed_command, timestamp, conn_id);
406+
return;
407+
}
408+
364409
// If the Set:Wait ratio is not 0, start off with WAITs
365410
if (m_config->wait_ratio.b &&
366411
(m_tot_wait_ops == 0 ||
@@ -416,16 +461,28 @@ void cluster_client::create_request(struct timeval timestamp, unsigned int conn_
416461
void cluster_client::handle_moved(unsigned int conn_id, struct timeval timestamp,
417462
request *request, protocol_response *response) {
418463
// update stats
419-
if (request->m_type == rt_get) {
420-
m_stats.update_moved_get_op(&timestamp,
464+
switch (request->m_type) {
465+
case rt_get:
466+
m_stats.update_moved_get_op(&timestamp,
421467
request->m_size + response->get_total_len(),
422468
ts_diff(request->m_sent_time, timestamp));
423-
} else if (request->m_type == rt_set) {
424-
m_stats.update_moved_set_op(&timestamp,
469+
break;
470+
case rt_set:
471+
m_stats.update_moved_set_op(&timestamp,
425472
request->m_size + response->get_total_len(),
426473
ts_diff(request->m_sent_time, timestamp));
427-
} else {
428-
assert(0);
474+
break;
475+
case rt_arbitrary: {
476+
arbitrary_request *ar = static_cast<arbitrary_request *>(request);
477+
m_stats.update_moved_arbitrary_op(&timestamp,
478+
request->m_size + response->get_total_len(),
479+
ts_diff(request->m_sent_time, timestamp),
480+
ar->index);
481+
break;
482+
}
483+
default:
484+
assert(0);
485+
break;
429486
}
430487

431488
// connection already issued 'cluster slots' command, wait for slots mapping to be updated
@@ -444,16 +501,28 @@ void cluster_client::handle_moved(unsigned int conn_id, struct timeval timestamp
444501
void cluster_client::handle_ask(unsigned int conn_id, struct timeval timestamp,
445502
request *request, protocol_response *response) {
446503
// update stats
447-
if (request->m_type == rt_get) {
448-
m_stats.update_ask_get_op(&timestamp,
449-
request->m_size + response->get_total_len(),
450-
ts_diff(request->m_sent_time, timestamp));
451-
} else if (request->m_type == rt_set) {
452-
m_stats.update_ask_set_op(&timestamp,
453-
request->m_size + response->get_total_len(),
454-
ts_diff(request->m_sent_time, timestamp));
455-
} else {
456-
assert(0);
504+
switch (request->m_type) {
505+
case rt_get:
506+
m_stats.update_ask_get_op(&timestamp,
507+
request->m_size + response->get_total_len(),
508+
ts_diff(request->m_sent_time, timestamp));
509+
break;
510+
case rt_set:
511+
m_stats.update_ask_set_op(&timestamp,
512+
request->m_size + response->get_total_len(),
513+
ts_diff(request->m_sent_time, timestamp));
514+
break;
515+
case rt_arbitrary: {
516+
arbitrary_request *ar = static_cast<arbitrary_request *>(request);
517+
m_stats.update_ask_arbitrary_op(&timestamp,
518+
request->m_size + response->get_total_len(),
519+
ts_diff(request->m_sent_time, timestamp),
520+
ar->index);
521+
break;
522+
}
523+
default:
524+
assert(0);
525+
break;
457526
}
458527
}
459528

cluster_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class cluster_client : public client {
5252

5353
// client manager api's
5454
virtual void handle_cluster_slots(protocol_response *r);
55+
virtual void create_arbitrary_request(const arbitrary_command* cmd, struct timeval& timestamp, unsigned int conn_id);
5556
virtual void create_request(struct timeval timestamp, unsigned int conn_id);
5657
virtual bool hold_pipeline(unsigned int conn_id);
5758
virtual void handle_response(unsigned int conn_id, struct timeval timestamp,

memtier_benchmark.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ static bool verify_cluster_option(struct benchmark_config *cfg) {
311311
} else if (cfg->unix_socket) {
312312
fprintf(stderr, "error: cluster mode dose not support unix-socket option.\n");
313313
return false;
314-
} else if (cfg->arbitrary_commands->is_defined()) {
315-
fprintf(stderr, "error: cluster mode dose not support arbitrary command option.\n");
316-
return false;
317314
}
318315

319316
return true;

run_stats.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ void run_stats::update_moved_set_op(struct timeval* ts, unsigned int bytes, unsi
196196
hdr_record_value(m_set_latency_histogram,latency);
197197
}
198198

199+
void run_stats::update_moved_arbitrary_op(struct timeval *ts, unsigned int bytes,
200+
unsigned int latency, size_t request_index) {
201+
roll_cur_stats(ts);
202+
203+
m_cur_stats.m_ar_commands.at(request_index).update_moved_op(bytes, latency);
204+
m_totals.update_op(bytes, latency);
205+
206+
struct hdr_histogram* hist = m_ar_commands_latency_histograms.at(request_index);
207+
hdr_record_value(hist,latency);
208+
}
209+
199210
void run_stats::update_ask_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency)
200211
{
201212
roll_cur_stats(ts);
@@ -214,6 +225,17 @@ void run_stats::update_ask_set_op(struct timeval* ts, unsigned int bytes, unsign
214225
hdr_record_value(m_set_latency_histogram,latency);
215226
}
216227

228+
void run_stats::update_ask_arbitrary_op(struct timeval *ts, unsigned int bytes,
229+
unsigned int latency, size_t request_index) {
230+
roll_cur_stats(ts);
231+
232+
m_cur_stats.m_ar_commands.at(request_index).update_ask_op(bytes, latency);
233+
m_totals.update_op(bytes, latency);
234+
235+
struct hdr_histogram* hist = m_ar_commands_latency_histograms.at(request_index);
236+
hdr_record_value(hist,latency);
237+
}
238+
217239
void run_stats::update_wait_op(struct timeval *ts, unsigned int latency)
218240
{
219241
roll_cur_stats(ts);
@@ -975,11 +997,18 @@ void run_stats::print_moved_sec_column(output_table &table) {
975997

976998
column.elements.push_back(*el.init_str("%12s ", "MOVED/sec"));
977999
column.elements.push_back(*el.init_str("%s", "-------------"));
978-
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_set_cmd.m_moved_sec));
979-
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_get_cmd.m_moved_sec));
980-
column.elements.push_back(*el.init_str("%12s ", "---"));
981-
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_moved_sec));
9821000

1001+
if (print_arbitrary_commands_results()) {
1002+
for (unsigned int i=0; i<m_totals.m_ar_commands.size(); i++) {
1003+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_ar_commands[i].m_moved_sec));
1004+
}
1005+
} else {
1006+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_set_cmd.m_moved_sec));
1007+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_get_cmd.m_moved_sec));
1008+
column.elements.push_back(*el.init_str("%12s ", "---"));
1009+
1010+
}
1011+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_moved_sec));
9831012
table.add_column(column);
9841013
}
9851014

@@ -989,11 +1018,17 @@ void run_stats::print_ask_sec_column(output_table &table) {
9891018

9901019
column.elements.push_back(*el.init_str("%12s ", "ASK/sec"));
9911020
column.elements.push_back(*el.init_str("%s", "-------------"));
992-
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_set_cmd.m_ask_sec));
1021+
if (print_arbitrary_commands_results()) {
1022+
for (unsigned int i=0; i<m_totals.m_ar_commands.size(); i++) {
1023+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_ar_commands[i].m_ask_sec));
1024+
}
1025+
} else {
1026+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_set_cmd.m_ask_sec));
9931027
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_get_cmd.m_ask_sec));
9941028
column.elements.push_back(*el.init_str("%12s ", "---"));
995-
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_ask_sec));
9961029

1030+
}
1031+
column.elements.push_back(*el.init_double("%12.2f ", m_totals.m_ask_sec));
9971032
table.add_column(column);
9981033
}
9991034

run_stats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ class run_stats {
119119

120120
void update_moved_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
121121
void update_moved_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
122+
void update_moved_arbitrary_op(struct timeval *ts, unsigned int bytes,
123+
unsigned int latency, size_t arbitrary_index);
122124

123125
void update_ask_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
124126
void update_ask_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
127+
void update_ask_arbitrary_op(struct timeval *ts, unsigned int bytes,
128+
unsigned int latency, size_t arbitrary_index);
125129

126130
void update_wait_op(struct timeval* ts, unsigned int latency);
127131
void update_arbitrary_op(struct timeval *ts, unsigned int bytes,

tests/include.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ def addTLSArgs(benchmark_specs, env):
8787
benchmark_specs['args'].append('--cacert={}'.format(TLS_CACERT))
8888

8989

90-
def get_default_memtier_config():
90+
def get_default_memtier_config(threads=10, clients=5, requests=1000):
9191
config = {
9292
"memtier_benchmark": {
9393
"binary": MEMTIER_BINARY,
94-
"threads": 10,
95-
"clients": 5,
96-
"requests": 1000
94+
"threads": threads,
95+
"clients": clients,
96+
"requests": requests
9797
},
9898
}
9999
return config
@@ -106,3 +106,4 @@ def ensure_clean_benchmark_folder(dirname):
106106
if os.path.exists(dirname):
107107
os.removedirs(dirname)
108108
os.makedirs(dirname)
109+

0 commit comments

Comments
 (0)