pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.03k stars 5.82k forks source link

Increase default value for prepared-plan-cache.capacity from 100 to 1000 #28665

Closed dbsid closed 2 years ago

dbsid commented 3 years ago

Enhancement

Typically a transaction for core-banking application will contains several hundreds of statement. The default value 100 for prepared-plan-cache.capacity is way too small, I'll propose to increase the default value to 1000+, anyway we have the memory-guard-ratio to protect from oom.

dbsid commented 3 years ago

running two business simulation of a core-bank application using single one connection, the prepared plan cache is up to ~500

image

tiancaiamao commented 2 years ago

Is this value configurable?

dbsid commented 2 years ago

Is this value configurable?

changing the values requires restart the tidb instance.

qw4990 commented 2 years ago

Could you please post more specified data to show the benefit and risks of increasing this config item? E.g. the latency, throughput, CPU usage, memory usage after increasing this config. @dbsid We need to prove that this modify is reasonable, for example, high benefits and low risks in some crucial scenarios.

shaoxiqian commented 2 years ago

@qw4990 test case: sysbench oltp_read_write.lua
threads:128 time: 600s sysbench --config-file=config oltp_read_write.lua --tables=32 --table-size=10000000 run

prepared-plan-cache.capacity 100vs1000 100 1000 diff(%)
cpu 1230% 1140% -7.31%
memory 1.54G 2.15G +39.61%
qps 16997.86 17636.77 +3.76%
tps 849.89 881.84 +3.76%
Queries Using Plan Cache OPS 10.3K 15.2K +47.57%
latency(avg) 150.59 145.13 -3.63%
95th percentile: 189.93 179.94 -5.26%

image

shaoxiqian commented 2 years ago

@qw4990 Two more test case for the value of prepared-plan-cache.capacity 100 vs 1000 Test case 1: systench Config: tables=32 table-size=10000000 threads=400、800 time:300s

oltp_update_non_index

400并发 800并发
1001000Diff(%)
QPS66824.2468946.85+3.18%
Latency (avg)5.985.8-3.01%
95th13.2212.30-6.96%
1001000Diff(%)
QPS77791.5379277.98+1.91%
Latency (avg)10.28 10.09-1.85%
95th23.10 22.69-1.77%

oltp_update_index

400并发 800并发
1001000Diff(%)
QPS27559.8227940.78+1.83%
Latency (avg)14.51114.31-1.38%
95th25.7425.28-1.79%
1001000Diff(%)
QPS30537.1632723.53+7.16%
Latency (avg)25.9724.44-1.79%
95th49.2144.17-10.24%

oltp_insert

400并发 800并发
1001000Diff(%)
QPS36563.1540551.89+10.91%
Latency (avg)21.8719.72-9.83%
95th46.6334.95-25.05%
1001000Diff(%)
QPS30537.1632723.53+7.16%
Latency (avg)25.9724.44-1.79%
95th49.2144.17-10.24%

oltp_point_select

400并发 800并发
1001000Diff(%)
QPS230893.54216613.29-6.18%
Latency (avg)1.731.85+6.94%
95th6.437.04+9.49%
1001000Diff(%)
QPS231852.84250362.21+7.98%
Latency (avg)3.453.19-7.54%
95th14.4612.75-11.83%
Test Case 2:TPC-C Config: threads=400、800 400并发 800并发
1001000Diff(%)
tpmC111233.7110291.9-0.85%
efficiency865.0%857.6%-0.86%
1001000Diff(%)
tpmC115434.1117087.7+1.43%
efficiency897.6%910.5%+1.44%
dbsid commented 2 years ago

@tiancaiamao @qw4990 From the test, for cases such as sysbench read-write on 32 tables, the number of prepared statement exceeds 100. By increasing the limit from 100 to 1000, we basically get more qps、less cpu usage and lower latency, at the cost of more memory usage. We think it's a reasonable tradeoff. In real-world, it's super hard for user to spot the size limitation of plan cache and extend it correspondingly. For other cases when the number of prepared statements does not exceeds 100 and just use query interface, we don't see performance penalty from this change.