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 May 19, 2022
1 parent 0cec3de commit 327278a
Show file tree
Hide file tree
Showing 4 changed files with 262 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 batch_insert.tuples_batch
-- @function insert_many
crud.insert_many = batch_insert.tuples_batch
crud.insert_many = stats.wrap(batch_insert.tuples_batch, stats.op.INSERT_MANY)

-- @refer batch_insert.objects_batch
-- @function insert_object_many
crud.insert_object_many = batch_insert.objects_batch
crud.insert_object_many = stats.wrap(batch_insert.objects_batch, 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 batch_replace.tuples_batch
-- @function replace_many
crud.replace_many = batch_replace.tuples_batch
crud.replace_many = stats.wrap(batch_replace.tuples_batch, stats.op.REPLACE_MANY)

-- @refer batch_replace.objects_batch
-- @function replace_object_many
crud.replace_object_many = batch_replace.objects_batch
crud.replace_object_many = stats.wrap(batch_replace.objects_batch, 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 batch_upsert.tuples_batch
-- @function upsert_many
crud.upsert_many = batch_upsert.tuples_batch
crud.upsert_many = stats.wrap(batch_upsert.tuples_batch, stats.op.UPSERT_MANY)

-- @refer batch_upsert.objects_batch
-- @function upsert_object_many
crud.upsert_object_many = batch_upsert.objects_batch
crud.upsert_object_many = stats.wrap(batch_upsert.objects_batch, 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
126 changes: 124 additions & 2 deletions test/integration/stats_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ local simple_operation_cases = {
},
op = 'insert',
},
{
name = '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',
},
{
name = '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',
},
{
name = 'get',
func = 'crud.get',
Expand Down Expand Up @@ -207,6 +231,30 @@ local simple_operation_cases = {
},
op = 'replace',
},
{
name = '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',
},
{
name = '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',
},
{
name = 'update',
prepare = function(g)
Expand Down Expand Up @@ -239,6 +287,38 @@ local simple_operation_cases = {
},
op = 'upsert',
},
{
name = 'upsert_many',
func = 'crud.upsert_many',
args = {
space_name,
{
{ 26, box.NULL, 'Ivan', 'Ivanov', 20, 'Moscow' },
{ 36, box.NULL, 'Oleg', 'Petrov', 25, 'Moscow' },
},
{
{{'+', 'age', 1}},
{{'+', 'age', 1}},
},
},
op = 'upsert_many',
},
{
name = 'upsert_object_many',
func = 'crud.upsert_object_many',
args = {
space_name,
{
{ id = 27, name = 'Ivan', last_name = 'Ivanov', age = 20, city = 'Moscow' },
{ id = 37, name = 'Oleg', last_name = 'Petrov', age = 25, city = 'Moscow' },
},
{
{{'+', 'age', 1}},
{{'+', 'age', 1}}
},
},
op = 'upsert_many',
},
{
name = 'delete',
func = 'crud.delete',
Expand Down Expand Up @@ -289,6 +369,20 @@ local simple_operation_cases = {
op = 'insert',
expect_error = true,
},
{
name = 'insert_many_error',
func = 'crud.insert_many',
args = { space_name, {{ 'id' }} },
op = 'insert_many',
expect_error = true,
},
{
name = 'insert_object_many_error',
func = 'crud.insert_object_many',
args = { space_name, {{ 'id' }} },
op = 'insert_many',
expect_error = true,
},
{
name = 'get_error',
func = 'crud.get',
Expand Down Expand Up @@ -325,6 +419,20 @@ local simple_operation_cases = {
op = 'replace',
expect_error = true,
},
{
name = 'replace_many_error',
func = 'crud.replace_many',
args = { space_name, {{ 'id' }} },
op = 'replace_many',
expect_error = true,
},
{
name = 'replace_object_many_error',
func = 'crud.replace_object_many',
args = { space_name, {{ 'id' }} },
op = 'replace_many',
expect_error = true,
},
{
name = 'update_error',
func = 'crud.update',
Expand All @@ -346,6 +454,20 @@ local simple_operation_cases = {
op = 'upsert',
expect_error = true,
},
{
name = 'upsert_many_error',
func = 'crud.upsert_many',
args = { space_name, {{ 'id' }}, {{{'+', 'age', 1}}} },
op = 'upsert_many',
expect_error = true,
},
{
name = 'upsert_object_many_error',
func = 'crud.upsert_object_many',
args = { space_name, {{ 'id' }}, {{{'+', 'age', 1}}} },
op = 'upsert_many',
expect_error = true,
},
{
name = 'delete_error',
func = 'crud.delete',
Expand Down Expand Up @@ -807,8 +929,8 @@ local function validate_metrics(g, metrics)
t.assert_type(stats_sum, 'table', '`tnt_crud_stats` summary metrics found')


local expected_operations = { 'insert', 'batch_insert', 'get', 'replace', 'update',
'upsert', 'batch_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 327278a

Please sign in to comment.