|
| 1 | +## YDB Token Application |
| 2 | +## A simple example of Spring Boot 2 Application working with YDB Database |
| 3 | + |
| 4 | +### How to build |
| 5 | + |
| 6 | +Requirements |
| 7 | +* Java 17 or newer |
| 8 | +* Maven 3.0.0 or newer |
| 9 | + |
| 10 | +To build the application as a single executable jar file, run the command: |
| 11 | +``` |
| 12 | +cd ydb-java-examples/jdbc/ydb-token-app |
| 13 | +mvn clean package spring-boot:repackage |
| 14 | +``` |
| 15 | +After that, the compiled `ydb-token-app-1.1.0-SNAPSHOT.jar` can be found in the target folder. |
| 16 | + |
| 17 | +### What this application does |
| 18 | + |
| 19 | +This application allows you to create a test table called `app_token` in the YDB database, populate it with data, and |
| 20 | +launch a test workload for parallel reading and writing to this table. During the test, the following operations will be |
| 21 | +performed in parallel in several threads: |
| 22 | +* Read a random token from the database - 50% of operations |
| 23 | +* Read and update a random token in the database - 40% of operations |
| 24 | +* Read and update 100 random tokens in the database - 10% of operations |
| 25 | + |
| 26 | +The statistics collected during the test include the number of operations performed, RPS (requests per second), and |
| 27 | +average execution time for each type of operation. There is also support for exporting application metrics in Prometheus |
| 28 | +format. |
| 29 | + |
| 30 | +### How to launch |
| 31 | + |
| 32 | +The application is built as a single executable jar file and can be run with the command: |
| 33 | +``` |
| 34 | +java -jar ydb-token-app-1.1.0-SNAPSHOT.jar <options> <commands> |
| 35 | +``` |
| 36 | +Where `options` are application parameters (see the Application Parameters section), and `commands` are the sequence of |
| 37 | +commands the application will execute one after the other. Currently, the following commands are supported: |
| 38 | +* clean - clean the database, the `app_token` table will be deleted |
| 39 | +* init - prepare the database, the empty `app_token` table will be created |
| 40 | +* load - load test data, the `app_token` table will be filled with initial data |
| 41 | +* run - start the test workload |
| 42 | + |
| 43 | +Commands can be used individually or sequenced, for example: |
| 44 | + |
| 45 | +Recreate the `app_token` table and initialize it with initial data: |
| 46 | +``` |
| 47 | +java -jar ydb-token-app-1.1.0-SNAPSHOT.jar --app.connection=grpcs://my-ydb:2135/my-database clean init load |
| 48 | +``` |
| 49 | + |
| 50 | +Start the test and then clean the database: |
| 51 | +``` |
| 52 | +java -jar ydb-token-app-1.1.0-SNAPSHOT.jar --app.connection=grpcs://my-ydb:2135/my-database run clean |
| 53 | +``` |
| 54 | + |
| 55 | +Recreate the `app_token` table, initialize it with data, and start the test: |
| 56 | +``` |
| 57 | +java -jar ydb-token-app-1.1.0-SNAPSHOT.jar --app.connection=grpcs://my-ydb:2135/my-database clean init load run |
| 58 | +``` |
| 59 | + |
| 60 | +### Application parameters |
| 61 | + |
| 62 | +Application parameters allow you to configure different aspects of the application's operation, primarily the database connection address. |
| 63 | +The main parameters list: |
| 64 | + |
| 65 | +* `app.connection` - database connection address. Specified as `<schema>://<endpoint>:<port>/<database>` |
| 66 | +* `app.threadsCount` - number of threads the application creates. Defaults to the number of CPU cores on the host. |
| 67 | +* `app.recordsCount` - number of records in the table used for testing. Default is 1 million. |
| 68 | +* `app.load.batchSize` - batch size for loading data when running the load command. Default is 1000. |
| 69 | +* `app.workload.duration` - test duration in seconds when running the run command. Default is 60 seconds. |
| 70 | +* `app.rpsLimit` - limit on the number of operations per second during the run command. By default, there is no limit (-1). |
| 71 | +* `app.pushMetrics` - flag indicating whether metrics should be exported to Prometheus; disabled by default. |
| 72 | +* `app.prometheusUrl` - endpoint of Prometheus to export metrics to. Default is http://localhost:9091. |
| 73 | + |
| 74 | +All parameters can be passed directly when launching the application (in the format `--param_name=value`) or can be |
| 75 | +preconfigured in an `application.properties` file saved next to the executable jar of the application. |
0 commit comments