tarantool / crud

Easy assess to data stored in vshard cluster
BSD 2-Clause "Simplified" License
40 stars 14 forks source link

It seems that crud is doing two selects in one `crud.get` #413

Open hackallcode opened 10 months ago

hackallcode commented 10 months ago

I call crud.get via go-tarantool using the primary key in this way: client.Do(crud.MakeGetRequest("users").Key([]any{reqUser.Token}), pool.ANY)

As a result, I look at the tnt_stats_op_total metric and see that one call and two selects are made on storage, which is strange. It seems that there should be one select, since this is a point query based on the primary key

DifferentialOrange commented 10 months ago

Original issue screenshots: image image

DifferentialOrange commented 10 months ago

Initial thoughts based on ./doc/playground.lua: it's not clear whether crud or not is the reason.

  1. You can get +2 SELECTs on a single crud.get.
  2. You can get +1 SELECTs on a single crud.get.
  3. You can get +N SELECTs if you wait for a several seconds on a crud cluster (without running any data operations).
  4. You can get +2 SELECTs on a single vshard space:get call.
  5. You can get +N SELECTs if you wait for a several seconds on a vshard cluster (without running any data operations).

See examples below. Beware that playground instance is a router and a storage at the same time, it also may affect the experiment.


tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
257
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
259
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
260
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
261
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
262
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
263
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
264
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
265
---
...

tarantool> crud.get('customers', 1); print(box.stat()['SELECT']['total'])
266
---
...

tarantool> print(box.stat()['SELECT']['total'])
268
---
...

If CRUD not configured.

diff --git a/doc/playground.lua b/doc/playground.lua
index d4e547f..e42720b 100755
--- a/doc/playground.lua
+++ b/doc/playground.lua
@@ -146,8 +146,8 @@ box.once('developers', function()
 end)

 -- Initialize crud.
-crud.init_storage()
-crud.init_router()
+-- crud.init_storage()
+-- crud.init_router()

 -- Start a console.
 console.start()

tarantool> vshard.router.callrw(1, 'box.space.customers:get', {1}); print(box.stat()['SELECT']['total'])
185
---
...

tarantool> vshard.router.callrw(1, 'box.space.customers:get', {1}); print(box.stat()['SELECT']['total'])
188
---
...

tarantool> vshard.router.callrw(1, 'box.space.customers:get', {1}); print(box.stat()['SELECT']['total'])
190
---
...

tarantool> vshard.router.callrw(1, 'box.space.customers:get', {1}); print(box.stat()['SELECT']['total'])
192
---
...

tarantool> vshard.router.callrw(1, 'box.space.customers:get', {1}); print(box.stat()['SELECT']['total'])
194
---
...
hackallcode commented 8 months ago

I noticed that for each crud replace in the metrics on the master, 1 select and 1 replace are added. It seems that this is the same select as in the get request.

I use the same query:

crud.MakeReplaceObjectRequest("users").Object(crud.MapObject{
    "token":   uuid.NewString(),
    "user_id": uuid.NewString(),
})