Skip to content

Commit

Permalink
Add stats collection and pert tests for batch methods
Browse files Browse the repository at this point in the history
Since we have PR #244 it will be nice to collect
statistics for batch operations too.
To establish the effectiveness of `crud.batch_insert()`
method compared to `crud.insert()`, perf tests were added.
`crud.insert()` in the loop and `crud.batch_insert()`
are compared for different batch sizes.

Closes #193
  • Loading branch information
AnaNek committed Jun 27, 2022
1 parent ad32c2b commit db644af
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 11 deletions.
12 changes: 6 additions & 6 deletions crud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ crud.insert_object = stats.wrap(insert.object, stats.op.INSERT)

-- @refer insert_many.tuples
-- @function insert_many
crud.insert_many = insert_many.tuples
crud.insert_many = stats.wrap(insert_many.tuples, stats.op.INSERT_MANY)

-- @refer insert_many.objects
-- @function insert_object_many
crud.insert_object_many = insert_many.objects
crud.insert_object_many = stats.wrap(insert_many.objects, stats.op.INSERT_MANY)

-- @refer get.call
-- @function get
Expand All @@ -56,11 +56,11 @@ crud.replace_object = stats.wrap(replace.object, stats.op.REPLACE)

-- @refer replace_many.tuples
-- @function replace_many
crud.replace_many = replace_many.tuples
crud.replace_many = stats.wrap(replace_many.tuples, stats.op.REPLACE_MANY)

-- @refer replace_many.objects
-- @function replace_object_many
crud.replace_object_many = replace_many.objects
crud.replace_object_many = stats.wrap(replace_many.objects, stats.op.REPLACE_MANY)

-- @refer update.call
-- @function update
Expand All @@ -72,11 +72,11 @@ crud.upsert = stats.wrap(upsert.tuple, stats.op.UPSERT)

-- @refer upsert_many.tuples
-- @function upsert_many
crud.upsert_many = upsert_many.tuples
crud.upsert_many = stats.wrap(upsert_many.tuples, stats.op.UPSERT_MANY)

-- @refer upsert_many.objects
-- @function upsert_object_many
crud.upsert_object_many = upsert_many.objects
crud.upsert_object_many = stats.wrap(upsert_many.objects, stats.op.UPSERT_MANY)

-- @refer upsert.object
-- @function upsert
Expand Down
6 changes: 6 additions & 0 deletions crud/stats/operation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
return {
-- INSERT identifies both `insert` and `insert_object`.
INSERT = 'insert',
-- INSERT_MANY identifies both `insert_many` and `insert_object_many`.
INSERT_MANY = 'insert_many',
GET = 'get',
-- REPLACE identifies both `replace` and `replace_object`.
REPLACE = 'replace',
-- REPLACE_MANY identifies both `replace_many` and `replace_object_many`.
REPLACE_MANY = 'replace_many',
UPDATE = 'update',
-- UPSERT identifies both `upsert` and `upsert_object`.
UPSERT = 'upsert',
-- UPSERT_MANY identifies both `upsert_many` and `upsert_object_many`.
UPSERT_MANY = 'upsert_many',
DELETE = 'delete',
-- SELECT identifies both `pairs` and `select`.
SELECT = 'select',
Expand Down
106 changes: 104 additions & 2 deletions test/integration/stats_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,28 @@ local simple_operation_cases = {
},
op = 'insert',
},
insert_many = {
func = 'crud.insert_many',
args = {
space_name,
{
{ 21, box.NULL, 'Ivan', 'Ivanov', 20, 'Moscow' },
{ 31, box.NULL, 'Oleg', 'Petrov', 25, 'Moscow' },
}
},
op = 'insert_many',
},
insert_object_many = {
func = 'crud.insert_object_many',
args = {
space_name,
{
{ id = 22, name = 'Ivan', last_name = 'Ivanov', age = 20, city = 'Moscow' },
{ id = 32, name = 'Oleg', last_name = 'Petrov', age = 25, city = 'Moscow' },
}
},
op = 'insert_many',
},
get = {
func = 'crud.get',
args = { space_name, { 12 } },
Expand Down Expand Up @@ -206,6 +228,28 @@ local simple_operation_cases = {
},
op = 'replace',
},
replace_many = {
func = 'crud.replace_many',
args = {
space_name,
{
{ 21, box.NULL, 'Peter', 'Ivanov', 40, 'Moscow' },
{ 31, box.NULL, 'Ivan', 'Petrov', 35, 'Moscow' },
}
},
op = 'replace_many',
},
replace_object_many = {
func = 'crud.replace_object_many',
args = {
space_name,
{
{ id = 22, name = 'Peter', last_name = 'Ivanov', age = 40, city = 'Moscow' },
{ id = 32, name = 'Ivan', last_name = 'Petrov', age = 35, city = 'Moscow' },
}
},
op = 'replace_many',
},
update = {
prepare = function(g)
helpers.insert_objects(g, space_name, {{
Expand Down Expand Up @@ -235,6 +279,28 @@ local simple_operation_cases = {
},
op = 'upsert',
},
upsert_many = {
func = 'crud.upsert_many',
args = {
space_name,
{
{{ 26, box.NULL, 'Ivan', 'Ivanov', 20, 'Moscow' }, {{'+', 'age', 1}}},
{{ 36, box.NULL, 'Oleg', 'Petrov', 25, 'Moscow' }, {{'+', 'age', 1}}},
},
},
op = 'upsert_many',
},
upsert_object_many = {
func = 'crud.upsert_object_many',
args = {
space_name,
{
{{ id = 27, name = 'Ivan', last_name = 'Ivanov', age = 20, city = 'Moscow' }, {{'+', 'age', 1}}},
{{ id = 37, name = 'Oleg', last_name = 'Petrov', age = 25, city = 'Moscow' }, {{'+', 'age', 1}}},
},
},
op = 'upsert_many',
},
delete = {
func = 'crud.delete',
args = { space_name, { 12 } },
Expand Down Expand Up @@ -277,6 +343,18 @@ local simple_operation_cases = {
op = 'insert',
expect_error = true,
},
insert_many_error = {
func = 'crud.insert_many',
args = { space_name, {{ 'id' }} },
op = 'insert_many',
expect_error = true,
},
insert_object_many_error = {
func = 'crud.insert_object_many',
args = { space_name, {{ 'id' }} },
op = 'insert_many',
expect_error = true,
},
get_error = {
func = 'crud.get',
args = { space_name, { 'id' } },
Expand Down Expand Up @@ -308,6 +386,18 @@ local simple_operation_cases = {
op = 'replace',
expect_error = true,
},
replace_many_error = {
func = 'crud.replace_many',
args = { space_name, {{ 'id' }} },
op = 'replace_many',
expect_error = true,
},
replace_object_many_error = {
func = 'crud.replace_object_many',
args = { space_name, {{ 'id' }} },
op = 'replace_many',
expect_error = true,
},
update_error = {
func = 'crud.update',
args = { space_name, { 'id' }, {{'+', 'age', 1}} },
Expand All @@ -326,6 +416,18 @@ local simple_operation_cases = {
op = 'upsert',
expect_error = true,
},
upsert_many_error = {
func = 'crud.upsert_many',
args = { space_name, { {{ 'id' }, {{'+', 'age', 1}}} }, },
op = 'upsert_many',
expect_error = true,
},
upsert_object_many_error = {
func = 'crud.upsert_object_many',
args = { space_name, { {{ 'id' }, {{'+', 'age', 1}}} } },
op = 'upsert_many',
expect_error = true,
},
delete_error = {
func = 'crud.delete',
args = { space_name, { 'id' } },
Expand Down Expand Up @@ -800,8 +902,8 @@ local function validate_metrics(g, metrics)
t.assert_type(stats_sum, 'table', '`tnt_crud_stats` summary metrics found')


local expected_operations = { 'insert', 'get', 'replace', 'update',
'upsert', 'delete', 'select', 'truncate', 'len', 'count', 'borders' }
local expected_operations = { 'insert', 'insert_many', 'get', 'replace', 'replace_many', 'update',
'upsert', 'upsert_many', 'delete', 'select', 'truncate', 'len', 'count', 'borders' }

if g.params.quantiles == true then
t.assert_items_equals(get_unique_label_values(quantile_stats, 'operation'), expected_operations,
Expand Down
Loading

0 comments on commit db644af

Please sign in to comment.