Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details about sysbench and the SQL Plan Cache #11011

Merged
merged 6 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 7 additions & 19 deletions benchmark/benchmark-tidb-using-sysbench.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ aliases: ['/docs/dev/benchmark/benchmark-tidb-using-sysbench/','/docs/dev/benchm

# How to Test TiDB Using Sysbench

It is recommended to use Sysbench 1.0 or later, which can be [downloaded here](https://github.com/akopytov/sysbench/releases/tag/1.0.14).
It is recommended to use Sysbench 1.0 or later, which can be [downloaded here](https://github.com/akopytov/sysbench/releases/tag/1.0.20).

## Test plan

Expand All @@ -19,6 +19,8 @@ server_configs:
log.level: "error"
```

It is also recommended to make sure [`tidb_enable_prepared_plan_cache`](/system-variables.md#tidb_enable_prepared_plan_cache-new-in-v610) is enabled and that you allow sysbench to use prepared statements by _not_ using `--db-ps-mode=disabled`. See the [SQL Prepared Execution Plan Cache](/sql-prepared-plan-cache.md) for documetnation about what the SQL plan cache does and how to monitor it.

### TiKV configuration

Higher log level also means better performance for TiKV.
Expand Down Expand Up @@ -109,10 +111,10 @@ Restart MySQL client and execute the following SQL statement to create a databas
create database sbtest;
```

Adjust the order in which Sysbench scripts create indexes. Sysbench imports data in the order of "Build Table -> Insert Data -> Create Index", which takes more time for TiDB to import data. Users can adjust the order to speed up the import of data. Suppose that you use the Sysbench version [1.0.14](https://github.com/akopytov/sysbench/tree/1.0.14). You can adjust the order in either of the following two ways:
Adjust the order in which Sysbench scripts create indexes. Sysbench imports data in the order of "Build Table -> Insert Data -> Create Index", which takes more time for TiDB to import data. Users can adjust the order to speed up the import of data. Suppose that you use the Sysbench version [1.0.20](https://github.com/akopytov/sysbench/tree/1.0.20). You can adjust the order in either of the following two ways:

- Download the modified [oltp_common.lua](https://raw.githubusercontent.com/pingcap/tidb-bench/master/sysbench/sysbench-patch/oltp_common.lua) file for TiDB and overwrite the `/usr/share/sysbench/oltp_common.lua` file with it.
- In `/usr/share/sysbench/oltp_common.lua`, move the lines [235](https://github.com/akopytov/sysbench/blob/1.0.14/src/lua/oltp_common.lua#L235)-[240](https://github.com/akopytov/sysbench/blob/1.0.14/src/lua/oltp_common.lua#L240) to be right behind the line 198.
- In `/usr/share/sysbench/oltp_common.lua`, move the lines [235-240](https://github.com/akopytov/sysbench/blob/1.0.20/src/lua/oltp_common.lua#L235-L240) to be right behind the line 198.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/akopytov/sysbench/blob/ebf1c90da05dea94648165e4f149abc20c979557/src/lua/oltp_common.lua#L235-L240

$ sysbench oltp_read_only help
sysbench 1.1.0-df89d34 (using bundled LuaJIT 2.1.0-beta3)

oltp_read_only options:
...
  --create_secondary[=on|off]   Create a secondary index in addition to the PRIMARY KEY [on]
...

On the line above that there is the link to https://raw.githubusercontent.com/pingcap/tidb-bench/master/sysbench/sysbench-patch/oltp_common.lua I think it would be good to either update that file to be based on 1.0.20. Maybe upload versions for both 1.0.14 and 1.0.20?
Maybe we can advise to use --create_secondary=off and then later create the indexes?
Maybe we should contribute an improvement to sysbench, e.g. an --create-indexes-at-the-end=on ? We might have other things to add as well like support for AUTO_RANDOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the warmup command was called prewarm in older versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbsid what do you think about updating the oltp_common.lua file for 1.0.20?


> **Note:**
>
Expand All @@ -130,22 +132,8 @@ sysbench --config-file=config oltp_point_select --tables=32 --table-size=1000000

To warm data, we load data from disk into the block cache of memory. The warmed data has significantly improved the overall performance of the system. It is recommended to warm data once after restarting the cluster.

Sysbench 1.0.14 does not provide data warming, so it must be done manually. If you are using [Sysbench of the master version](https://github.com/akopytov/sysbench/tree/master), you can use the data warming feature included in the tool itself.

Take a table sbtest7 in Sysbench as an example. Execute the following SQL to warming up data:

{{< copyable "sql" >}}

```sql
SELECT COUNT(pad) FROM sbtest7 USE INDEX (k_7);
```

Collecting statistics helps the optimizer choose a more accurate execution plan. The `analyze` command can be used to collect statistics on the table sbtest. Each table needs statistics.

{{< copyable "sql" >}}

```sql
ANALYZE TABLE sbtest7;
```bash
sysbench --config-file=config oltp_point_select --tables=32 --table-size=10000000 warmup
```

### Point select test command
Expand Down
Binary file added media/performance/sql_plan_cache.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion sql-prepared-plan-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,14 @@ mysql> select @@last_plan_from_cache; -- Reuse the last plan
| 1 |
+------------------------+
1 row in set (0.00 sec)
```
```

<CustomContent platform="tidb">

### Monitoring

In [the Grafana dashboard](/grafana-tidb-dashboard.md) on the TiDB page in the Executor section there are the "Queries Using Plan Cache OPS" and "Plan Cache Miss OPS" graphs. These graphs can be used to check if both TiDB and the application are configured correctly to allow the SQL Plan Cache to work correctly. On the same page, but in the Server section there is a "Prepared Statement Count" graph, which should show a non-zero value if the application uses prepared statements, which is required for the SQL Plan Cache to function correctly.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

![`sql_plan_cache`](/media/performance/sql_plan_cache.png)

</CustomContent>