Project: YDB (App Definition and Development / Database)
File: workload-kv.md

A simple load type using a YDB database as a Key-Value storage. This load test runs several types of load: : Using the UPSERT operation, inserts rows that are tuples (key1, key2, ... keyK, value1, value2, ... valueN) into the table created previously with the init command, the K and N numbers are specified in the settings. : The function is the same as the upsert load, only the INSERT operation is used for insertion. : Reads data using the SELECT WHERE key = $key operation. A query always affects all table columns, but isn't always a point query, and the number of primary key variations can be controlled using parameters. : Reads data using the ReadRows operation, which performs faster key reading than select operation. A query always affects all table columns, but isn't always a point query, and the number of primary key variations can be controlled using parameters. : Simultaneously writes and reads data, additionally checking that all written data is successfully read. To get started, you must create tables. When creating them, you can specify how many rows to insert during initialization: ```bash {{ ydb-cli }} workload kv init [init options...] ``` `init options`: . View a description of the command to initialize the table: ```bash {{ ydb-cli }} workload kv init --help ``` Parameter name | Parameter description | `--init-upserts <value>` | Number of insertion operations to be performed during initialization. Default: 1000. `--min-partitions` | Minimum number of shards for tables. Default: 40. `--partition-size` | Maximum size of one shard (the `AUTOPARTITIONINGPARTITIONSIZEMB` setting). Default: 2000. `--auto-partition` | Enabling/disabling auto-sharding. Possible values: 0 or 1. Default: 1. `--max-first-key` | Maximum value of the primary key of the table. Default: $2^{64} 1$. `--len` | The size of the rows in bytes that are inserted into the table as values. Default: 8. `--cols` | Number of columns in the table. Default: 2 counting Key. `--int-cols` | Number of first columns in the table that will have the `Uint64` type; subsequent columns will have the `String` type. Default: 1. `--key-cols` | Number of first columns in the table included in the key. Default: 1. `--rows` | Number of affected rows in one query. Default: 1. The following command is used to create a table: ```yql CREATE TABLE `kv_test`( c0 Uint64, c1 Uint64, ... cI Uint64, cI+1 String, ... cN String, PRIMARY KEY(c0, c1,

cK)) WITH ( AUTOPARTITIONINGBY_LOAD = ENABLED, AUTOPARTITIONINGMINPARTITIONSCOUNT = partsNum, UNIFORM_PARTITIONS = partsNum, AUTOPARTITIONINGPARTITIONSIZEMB = partSize, AUTOPARTITIONINGMAXPARTITIONSCOUNT = 1000 ) ) ``` Example of a command to create a table with 1000 rows: ```bash {{ ydb-cli }} workload kv init --init-upserts 1000 ``` When the work is complete, you can delete the table: ```bash {{ ydb-cli }} workload kv clean ``` The following YQL command is executed: ```sql DROP TABLE `kv_test` ``` ```bash {{ ydb-cli }} workload kv clean ``` To run the load, execute the command: ```bash {{ ydb-cli }} workload kv run [workload type...] [global workload options...] [specific workload options...] ``` During this test, workload statistics for each time window are displayed on the screen. `workload type`: . `global workload options`: . `specific workload options`: Options of a specific load type. See the description of the command to run the data load: ```bash {{ ydb-cli }} workload kv run --help ``` Parameter name | Short name | Parameter description || `--seconds <value>` | `-s <value>` | Duration of the test, in seconds. Default: 10. `--threads <value>` | `-t <value>` | The number of parallel threads creating the load. Default: 10. `--rate <value>` | - | Total rate for all threads, in requests per second. Default: 0 (no rate limit). `--quiet` | - | Outputs only the total result. `--print-timestamp` | - | Print the time together with the statistics of each time window. `--client-timeout` | - | . `--operation-timeout` | - | . `--cancel-after` | - | . `--window` | - | Statistics collection window in seconds. Default: 1. `--max-first-key` | - | Maximum value of the primary key of the table. Default: $2^{64} - 1$. `--cols` | - | Number of columns in the table. Default: 2 counting Key. `--int-cols` | - | Number of first columns in the table that will have the `Uint64` type; subsequent columns will have the `String` type. Default: 1. `--key-cols` | - | Number of first columns in the table included in the key. Default: 1. `--rows` | - | Number of affected rows in one query. Default: 1. This load type inserts tuples (key, value1, value2, ..., valueN) To run this type of load, execute the command: ```bash {{ ydb-cli }} workload kv run upsert [global workload options...] [specific workload options...] ``` `global workload options`: . `specific workload options`:

For example, for the parameters `--rows 2 --cols 3 --int-cols 2`, the YQL query will look like this: ```yql DECLARE $c0_0 AS Uint64; DECLARE $c0_1 AS Uint64; DECLARE $c0_2 AS String; DECLARE $c1_0 AS Uint64; DECLARE $c1_1 AS Uint64; DECLARE $c1_2 AS String; UPSERT INTO `kvtest` (c0, c1, c2) VALUES ($c00, $c01, $c02), ($c10, $c11, $c1_2) ``` Parameter name | Parameter description | `--len` | The size of the rows in bytes that are inserted into the table as values. Default: 8. This load type inserts tuples (key, value1, value2, ..., valueN) To run this type of load, execute the command: ```bash {{ ydb-cli }} workload kv run insert [global workload options...] [specific workload options...] ``` `global workload options`: . `specific workload options`: . For example, for the parameters `--rows 2 --cols 3 --int-cols 2`, the YQL query will look like this: ```yql DECLARE $c0_0 AS Uint64; DECLARE $c0_1 AS Uint64; DECLARE $c0_2 AS String; DECLARE $c1_0 AS Uint64; DECLARE $c1_1 AS Uint64; DECLARE $c1_2 AS String; INSERT INTO `kvtest` (c0, c1, c2) VALUES ($c00, $c01, $c02), ($c10, $c11, $c1_2) ``` Parameter name | Parameter description | `--len` | The size of the rows in bytes that are inserted into the table as values. Default: 8. This type of load creates SELECT queries that return rows based on an exact match of the primary key. To run this type of load, execute the command: ```bash {{ ydb-cli }} workload kv run select [global workload options...] ``` `global workload options`: . For example, for the parameters `--rows 2 --cols 3 --int-cols 2`, the YQL query will look like this: ```yql DECLARE $r0_0 AS Uint64; DECLARE $r0_1 AS Uint64; DECLARE $r1_0 AS Uint64; DECLARE $r1_1 AS Uint64; SELECT c0, c1, c2 FROM `kvtest` WHERE c0 = $r00 AND c1 = $r01 OR c0 = $r10 AND c1 = $r1_1 ``` This type of load creates ReadRows queries that return rows based on an exact match of the primary key. To run this type of load, execute the command: ```bash {{ ydb-cli }} workload kv run read-rows [global workload options...] ``` `global workload options`: . This type of load simultaneously writes and reads tuples (key, value1, value2, ..., valueN), additionally checking that all written data is successfully read. To run this type of load, execute the command: ```bash {{ ydb-cli }} workload kv run mixed [global workload options...] [specific workload options...] ``` `global workload options`: . `specific workload options` - . Parameter name | Parameter description | `--len` | The size of the rows in bytes that are inserted into the table as values. Default: 8. `--change-partitions-size` | Enabling/disabling random modification of the `AUTOPARTITIONINGPARTITIONSIZEMB` setting. Possible values: 0 or 1. Default: 0. `--do-select` | Enabling/disabling reads using the query. Possible values: 0 or 1. Default: 1. `--do-read-rows` | Enabling/disabling reads using the query. Possible values: 0 or 1. Default: 1.