Skip to content
Snippets Groups Projects
Commit 6b313132 authored by Daniil Medvedev's avatar Daniil Medvedev Committed by Konstantin Osipov
Browse files

gh-969 configurable tuple bench

parent c36c989f
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ tuple_bench(box_function_ctx_t *ctx, const char *args, const char *args_end)
uint32_t space_id = box_space_id_by_name(SPACE_NAME, strlen(SPACE_NAME));
uint32_t index_id = box_index_id_by_name(space_id, INDEX_NAME,
strlen(INDEX_NAME));
if (space_id == BOX_ID_NIL || index_id == BOX_ID_NIL) {
return box_error_raise(ER_PROC_C,
"Can't find index %s in space %s",
......@@ -26,50 +27,42 @@ tuple_bench(box_function_ctx_t *ctx, const char *args, const char *args_end)
say_debug("space_id = %u, index_id = %u", space_id, index_id);
char tuple_buf[4][64];
char *tuple_end[4] = {tuple_buf[0], tuple_buf[1], tuple_buf[2], tuple_buf[3]};
if(1) {
tuple_end[0] = mp_encode_array(tuple_end[0], 2);
tuple_end[0] = mp_encode_uint(tuple_end[0], 2);
tuple_end[0] = mp_encode_str(tuple_end[0], "bce", strlen("abb"));
tuple_end[1] = mp_encode_array(tuple_end[1], 2);
tuple_end[1] = mp_encode_uint(tuple_end[1], 2);
tuple_end[1] = mp_encode_str(tuple_end[1], "abb", strlen("abb"));
tuple_end[2] = mp_encode_array(tuple_end[2], 2);
tuple_end[2] = mp_encode_uint(tuple_end[2], 1);
tuple_end[2] = mp_encode_str(tuple_end[2], "abb", strlen("abb"));
tuple_end[3] = mp_encode_array(tuple_end[3], 2);
tuple_end[3] = mp_encode_uint(tuple_end[3], 3);
tuple_end[3] = mp_encode_str(tuple_end[3], "ccd", strlen("abb"));
} else if(0){
tuple_end[0] = mp_encode_array(tuple_end[0], 1);
tuple_end[0] = mp_encode_uint(tuple_end[0], 2);
tuple_end[1] = mp_encode_array(tuple_end[1], 1);
tuple_end[1] = mp_encode_uint(tuple_end[1], 1);
tuple_end[2] = mp_encode_array(tuple_end[2], 1);
tuple_end[2] = mp_encode_uint(tuple_end[2], 1);
tuple_end[3] = mp_encode_array(tuple_end[3], 1);
tuple_end[3] = mp_encode_uint(tuple_end[3], 3);
} else {
tuple_end[0] = mp_encode_array(tuple_end[0], 1);
tuple_end[0] = mp_encode_str(tuple_end[0], "bce", strlen("abb"));
tuple_end[1] = mp_encode_array(tuple_end[1], 1);
tuple_end[1] = mp_encode_str(tuple_end[1], "abb", strlen("abb"));
tuple_end[2] = mp_encode_array(tuple_end[2], 1);
tuple_end[2] = mp_encode_str(tuple_end[2], "abb", strlen("abb"));
tuple_end[3] = mp_encode_array(tuple_end[3], 1);
tuple_end[3] = mp_encode_str(tuple_end[3], "ccd", strlen("abb"));
char *tuple_end[4] = {tuple_buf[0], tuple_buf[1],
tuple_buf[2], tuple_buf[3]};
const uint64_t test_numbers[4] = {2, 2, 1, 3};
const char test_strings[4][4] = {"bce", "abb", "abb", "ccd"};
/* get key types from args, and build test tuples with according types*/
uint32_t arg_count = mp_decode_array(&args);
if (arg_count < 1) {
return box_error_raise(ER_PROC_C, "%s",
"invalid argument count");
}
uint32_t n = mp_decode_array(&args);
uint32_t knum = 0, kstr = 0;
for (uint32_t k = 0; k < 4; k++) {
const char *field = args;
tuple_end[k] = mp_encode_array(tuple_end[k], n);
for (uint32_t i = 0; i < n; i++, field += 3) {
if (mp_decode_strl(&field) != 3) {
say_error("Arguments must be \"STR\" or \"NUM\"");
return -1;
}
if (memcmp(field, "NUM", 3) == 0) {
tuple_end[k] = mp_encode_uint(tuple_end[k],
test_numbers[knum]);
knum = (knum + 1) % 4;
} else if (memcmp(field, "STR", 3) == 0) {
tuple_end[k] = mp_encode_str(tuple_end[k],
test_strings[kstr],
strlen(test_strings[kstr]));
kstr = (kstr + 1) % 4;
} else {
say_error("Arguments must be \"STR\" or \"NUM\"");
return -1;
}
}
}
//tuple_cmp = tuple_compare_with_key;
double t = proctime();
box_tuple_t *tuple;
for (int i = 0; i < 80000000; i++) {
......
......@@ -16,7 +16,10 @@ box.schema.user.grant('guest', 'execute', 'function', 'tuple_bench')
space = box.schema.space.create('tester')
---
...
_ = space:create_index('primary', {type = 'TREE', parts = {1, 'NUM', 2, 'STR'}})
key_parts = {1, 'NUM', 2, 'STR'}
---
...
_ = space:create_index('primary', {type = 'TREE', parts = key_parts})
---
...
box.schema.user.grant('guest', 'read,write', 'space', 'tester')
......@@ -41,7 +44,13 @@ prof.start('tuple.prof')
---
- true
...
c:call('tuple_bench')
key_types = {}
---
...
for i = 1, #key_parts, 2 do table.insert(key_types, key_parts[i + 1]) end
---
...
c:call('tuple_bench', key_types)
---
- []
...
......
......@@ -7,7 +7,8 @@ c = net:new(os.getenv("LISTEN"))
box.schema.func.create('tuple_bench', {language = "C"})
box.schema.user.grant('guest', 'execute', 'function', 'tuple_bench')
space = box.schema.space.create('tester')
_ = space:create_index('primary', {type = 'TREE', parts = {1, 'NUM', 2, 'STR'}})
key_parts = {1, 'NUM', 2, 'STR'}
_ = space:create_index('primary', {type = 'TREE', parts = key_parts})
box.schema.user.grant('guest', 'read,write', 'space', 'tester')
box.space.tester:insert({1, "abc", 100})
......@@ -17,7 +18,10 @@ box.space.tester:insert({3, "ccd", 200})
prof = require('gperftools.cpu')
prof.start('tuple.prof')
c:call('tuple_bench')
key_types = {}
for i = 1, #key_parts, 2 do table.insert(key_types, key_parts[i + 1]) end
c:call('tuple_bench', key_types)
prof.flush()
prof.stop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment