目录
innodb-architecture
default-config
innodb_buffer_pool_size
Innodb_buffer_pool_instances
innodb_flush_log_at_trx_commit
innodb_log_buffer_size
innodb_log_file_size
innodb_log_file_in_group
innodb_file_per_table
innodb_thread_concurrency
innodb_read_io_threads
innodb_read_io_threads
bulk_insert_buffer_size
innodb architecture
default config
SELECT @@innodb_buffer_pool_size/1024/1024/1024;
+--------------------------------------------+
| @@innodb_buffer_pool_size/1024/1024/1024 |
|--------------------------------------------|
| 0.125000000000 |
+--------------------------------------------+
SELECT @@innodb_buffer_pool_chunk_size/1024/1024/1024;
+--------------------------------------------------+
| @@innodb_buffer_pool_chunk_size/1024/1024/1024 |
|--------------------------------------------------|
| 0.125000000000 |
+--------------------------------------------------+
SELECT @@innodb_buffer_pool_instances;
+----------------------------------+
| @@innodb_buffer_pool_instances |
|----------------------------------|
| 1 |
+----------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.873 seconds
Minimum number of seconds to run all queries: 0.873 seconds
Maximum number of seconds to run all queries: 0.873 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.987 seconds
Minimum number of seconds to run all queries: 0.987 seconds
Maximum number of seconds to run all queries: 0.987 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt install -y --allow-unauthenticated sysbench
CREATE DATABASE sbtest;
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 644.19 qps: 12893.33 (r/w/o: 9025.68/2578.77/1288.88) lat (ms,95%): 12.52 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 5 tps: 643.80 qps: 12876.06 (r/w/o: 9013.24/2575.21/1287.61) lat (ms,95%): 13.70 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 666.48 qps: 13325.74 (r/w/o: 9328.58/2664.21/1332.95) lat (ms,95%): 12.98 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 652.01 qps: 13044.17 (r/w/o: 9130.69/2609.35/1304.13) lat (ms,95%): 13.95 err/s: 0.10 reconn/s: 0.00
[ 50s ] thds: 5 tps: 664.30 qps: 13287.56 (r/w/o: 9301.17/2657.79/1328.60) lat (ms,95%): 12.52 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 668.09 qps: 13360.09 (r/w/o: 9352.73/2671.18/1336.19) lat (ms,95%): 12.75 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 551544
write: 157582
other: 78791
total: 787917
transactions: 39395 (656.45 per sec.)
queries: 787917 (13129.36 per sec.)
ignored errors: 1 (0.02 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0101s
total number of events: 39395
Latency (ms):
min: 2.31
avg: 7.61
max: 83.86
95th percentile: 12.98
sum: 299935.56
Threads fairness:
events (avg/stddev): 7879.0000/33.20
execution time (avg/stddev): 59.9871/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
在线交易处理(OLTP, Online transaction processing)
innodb_buffer_pool_size
SET GLOBAL innodb_buffer_pool_size=4294967296;
SHOW STATUS WHERE Variable_name='InnoDB_buffer_pool_resize_status';
+----------------------------------+----------------------------------------------------+
| Variable_name | Value |
|----------------------------------+----------------------------------------------------|
| Innodb_buffer_pool_resize_status | Completed resizing buffer pool at 181117 20:30:55. |
+----------------------------------+----------------------------------------------------+
SELECT @@innodb_buffer_pool_size/1024/1024/1024;
+--------------------------------------------+
| @@innodb_buffer_pool_size/1024/1024/1024 |
|--------------------------------------------|
| 4.000000000000 |
+--------------------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.870 seconds
Minimum number of seconds to run all queries: 0.870 seconds
Maximum number of seconds to run all queries: 0.870 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.905 seconds
Minimum number of seconds to run all queries: 0.905 seconds
Maximum number of seconds to run all queries: 0.905 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 592.30 qps: 11855.41 (r/w/o: 8299.13/2371.18/1185.09) lat (ms,95%): 14.46 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 5 tps: 653.40 qps: 13064.34 (r/w/o: 9145.93/2611.61/1306.80) lat (ms,95%): 13.46 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 640.21 qps: 12801.17 (r/w/o: 8959.92/2560.83/1280.42) lat (ms,95%): 14.46 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 679.00 qps: 13582.58 (r/w/o: 9508.59/2716.00/1358.00) lat (ms,95%): 11.45 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 5 tps: 692.09 qps: 13841.39 (r/w/o: 9688.46/2768.76/1384.18) lat (ms,95%): 11.65 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 667.51 qps: 13354.03 (r/w/o: 9347.89/2671.13/1335.01) lat (ms,95%): 12.98 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 549514
write: 157004
other: 78502
total: 785020
transactions: 39251 (654.07 per sec.)
queries: 785020 (13081.47 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0085s
total number of events: 39251
Latency (ms):
min: 2.44
avg: 7.64
max: 132.32
95th percentile: 12.98
sum: 299926.10
Threads fairness:
events (avg/stddev): 7850.2000/27.51
execution time (avg/stddev): 59.9852/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置Innodb_buffer_pool_size=4G对性能无明显提升
Innodb_buffer_pool_instances
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
innodb_buffer_pool_size = 4000M
innodb_buffer_pool_instances = 4
service mysql restart
SELECT @@innodb_buffer_pool_size/1024/1024/1024;
+--------------------------------------------+
| @@innodb_buffer_pool_size/1024/1024/1024 |
|--------------------------------------------|
| 4.000000000000 |
+--------------------------------------------+
SELECT @@innodb_buffer_pool_instances;
+----------------------------------+
| @@innodb_buffer_pool_instances |
|----------------------------------|
| 4 |
+----------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.871 seconds
Minimum number of seconds to run all queries: 0.871 seconds
Maximum number of seconds to run all queries: 0.871 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.943 seconds
Minimum number of seconds to run all queries: 0.943 seconds
Maximum number of seconds to run all queries: 0.943 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 578.29 qps: 11574.19 (r/w/o: 8102.75/2314.36/1157.08) lat (ms,95%): 15.83 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 5 tps: 647.91 qps: 12951.20 (r/w/o: 9065.17/2590.42/1295.61) lat (ms,95%): 13.46 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 668.99 qps: 13384.88 (r/w/o: 9370.21/2676.48/1338.19) lat (ms,95%): 12.98 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 651.11 qps: 13018.91 (r/w/o: 9112.88/2603.92/1302.11) lat (ms,95%): 13.22 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 5 tps: 700.60 qps: 14018.27 (r/w/o: 9812.55/2804.41/1401.31) lat (ms,95%): 11.87 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 689.21 qps: 13780.45 (r/w/o: 9646.80/2755.23/1378.41) lat (ms,95%): 12.52 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 551138
write: 157468
other: 78734
total: 787340
transactions: 39367 (655.97 per sec.)
queries: 787340 (13119.38 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0119s
total number of events: 39367
Latency (ms):
min: 2.29
avg: 7.62
max: 173.95
95th percentile: 13.22
sum: 299937.15
Threads fairness:
events (avg/stddev): 7873.4000/25.08
execution time (avg/stddev): 59.9874/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置Innodb_buffer_pool_instances=4对性能无明显提升
innodb_flush_log_at_trx_commit
SET GLOBAL innodb_flush_log_at_trx_commit=2;
SELECT @@innodb_flush_log_at_trx_commit;
+------------------------------------+
| @@innodb_flush_log_at_trx_commit |
|------------------------------------|
| 2 |
+------------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.842 seconds
Minimum number of seconds to run all queries: 0.842 seconds
Maximum number of seconds to run all queries: 0.842 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.860 seconds
Minimum number of seconds to run all queries: 0.860 seconds
Maximum number of seconds to run all queries: 0.860 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 682.17 qps: 13650.15 (r/w/o: 9556.12/2729.09/1364.95) lat (ms,95%): 13.46 err/s: 0.10 reconn/s: 0.00
[ 20s ] thds: 5 tps: 787.81 qps: 15757.55 (r/w/o: 11031.10/3150.83/1575.61) lat (ms,95%): 10.27 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 792.90 qps: 15856.37 (r/w/o: 11098.98/3171.59/1585.80) lat (ms,95%): 10.65 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 800.80 qps: 16019.14 (r/w/o: 11214.13/3203.31/1601.70) lat (ms,95%): 10.46 err/s: 0.10 reconn/s: 0.00
[ 50s ] thds: 5 tps: 819.50 qps: 16389.78 (r/w/o: 11472.58/3278.20/1639.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 816.30 qps: 16325.79 (r/w/o: 11427.69/3265.40/1632.70) lat (ms,95%): 10.27 err/s: 0.20 reconn/s: 0.00
SQL statistics:
queries performed:
read: 658070
write: 188009
other: 94006
total: 940085
transactions: 47001 (783.21 per sec.)
queries: 940085 (15665.22 per sec.)
ignored errors: 4 (0.07 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0093s
total number of events: 47001
Latency (ms):
min: 1.54
avg: 6.38
max: 125.90
95th percentile: 10.84
sum: 299900.90
Threads fairness:
events (avg/stddev): 9400.2000/96.39
execution time (avg/stddev): 59.9802/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置innodb_flush_log_at_trx_commit=2对性能有大约20%提升
innodb_log_buffer_size
innodb_log_buffer_size通常使用默认配置即可
SELECT @@innodb_log_buffer_size/1024/1024;
+--------------------------------------+
| @@innodb_log_buffer_size/1024/1024 |
|--------------------------------------|
| 16.00000000 |
+--------------------------------------+
innodb_log_file_size
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
innodb_buffer_pool_size = 4000M
innodb_buffer_pool_instances = 4
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
service mysql restart
SELECT @@innodb_log_file_size/1024/1024;
+------------------------------------+
| @@innodb_log_file_size/1024/1024 |
|------------------------------------|
| 256.00000000 |
+------------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.835 seconds
Minimum number of seconds to run all queries: 0.835 seconds
Maximum number of seconds to run all queries: 0.835 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.863 seconds
Minimum number of seconds to run all queries: 0.863 seconds
Maximum number of seconds to run all queries: 0.863 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 704.07 qps: 14091.13 (r/w/o: 9864.90/2817.49/1408.74) lat (ms,95%): 11.65 err/s: 0.10 reconn/s: 0.00
[ 20s ] thds: 5 tps: 817.31 qps: 16345.45 (r/w/o: 11442.61/3268.23/1634.62) lat (ms,95%): 9.91 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 851.70 qps: 17035.31 (r/w/o: 11923.94/3407.98/1703.39) lat (ms,95%): 9.39 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 856.09 qps: 17120.12 (r/w/o: 11984.30/3423.64/1712.17) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 5 tps: 868.41 qps: 17366.69 (r/w/o: 12156.20/3473.66/1736.83) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 871.50 qps: 17429.51 (r/w/o: 12201.01/3485.50/1743.00) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 695772
write: 198789
other: 99395
total: 993956
transactions: 49697 (828.15 per sec.)
queries: 993956 (16563.36 per sec.)
ignored errors: 1 (0.02 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0076s
total number of events: 49697
Latency (ms):
min: 1.78
avg: 6.03
max: 128.59
95th percentile: 9.73
sum: 299888.41
Threads fairness:
events (avg/stddev): 9939.4000/115.20
execution time (avg/stddev): 59.9777/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置innodb_log_file_size=256M对性能有大约4%提升
innodb_log_files_in_group
SELECT @@innodb_log_files_in_group;
+-------------------------------+
| @@innodb_log_files_in_group |
|-------------------------------|
| 2 |
+-------------------------------+
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
innodb_buffer_pool_size = 4000M
innodb_buffer_pool_instances = 4
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
service mysql restart
SELECT @@innodb_log_files_in_group;
+-------------------------------+
| @@innodb_log_files_in_group |
|-------------------------------|
| 3 |
+-------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.838 seconds
Minimum number of seconds to run all queries: 0.838 seconds
Maximum number of seconds to run all queries: 0.838 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.869 seconds
Minimum number of seconds to run all queries: 0.869 seconds
Maximum number of seconds to run all queries: 0.869 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 748.16 qps: 14969.37 (r/w/o: 10479.79/2992.75/1496.83) lat (ms,95%): 10.84 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 5 tps: 834.60 qps: 16693.77 (r/w/o: 11686.05/3338.41/1669.31) lat (ms,95%): 9.56 err/s: 0.10 reconn/s: 0.00
[ 30s ] thds: 5 tps: 862.90 qps: 17255.30 (r/w/o: 12077.90/3451.60/1725.80) lat (ms,95%): 8.90 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 834.20 qps: 16688.41 (r/w/o: 11682.71/3337.20/1668.50) lat (ms,95%): 9.56 err/s: 0.10 reconn/s: 0.00
[ 50s ] thds: 5 tps: 857.80 qps: 17157.59 (r/w/o: 12011.09/3430.80/1715.70) lat (ms,95%): 9.22 err/s: 0.10 reconn/s: 0.00
[ 60s ] thds: 5 tps: 876.30 qps: 17524.97 (r/w/o: 12267.18/3505.19/1752.60) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 702086
write: 200585
other: 100295
total: 1002966
transactions: 50146 (835.64 per sec.)
queries: 1002966 (16713.61 per sec.)
ignored errors: 3 (0.05 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0073s
total number of events: 50146
Latency (ms):
min: 1.77
avg: 5.98
max: 163.37
95th percentile: 9.56
sum: 299884.99
Threads fairness:
events (avg/stddev): 10029.2000/72.68
execution time (avg/stddev): 59.9770/0.00
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置innodb_log_files_in_group=3对性能有不到1%的提升
innodb_file_per_table
innodb_file_per_table通常使用默认配置即可
SELECT @@innodb_file_per_table;
+---------------------------+
| @@innodb_file_per_table |
|---------------------------|
| 1 |
+---------------------------+
innodb_thread_concurrency
innodb_thread_concurrency = CPU count * 2 默认配置=0即不限制线程数
SELECT @@innodb_thread_concurrency;
+-------------------------------+
| @@innodb_thread_concurrency |
|-------------------------------|
| 0 |
+-------------------------------+
innodb_read_io_threads
innodb_read_io_threads = CPU count 如果读操作>写操作 配置innodb_read_io_threads>innodb_write_io_threads
SELECT @@innodb_read_io_threads;
+----------------------------+
| @@innodb_read_io_threads |
|----------------------------|
| 4 |
+----------------------------+
innodb_write_io_threads
innodb_write_io_threads = CPU count 如果写操作>读操作 配置
innodb_write_io_threads>innodb_read_io_threads
SELECT @@innodb_write_io_threads;
+-----------------------------+
| @@innodb_write_io_threads |
|-----------------------------|
| 4 |
+-----------------------------+
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
innodb_buffer_pool_size = 4000M
innodb_buffer_pool_instances = 4
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_write_io_threads=8
service mysql restart
SELECT @@innodb_write_io_threads;
+-----------------------------+
| @@innodb_write_io_threads |
|-----------------------------|
| 8 |
+-----------------------------+
bulk_insert_buffer_size
SELECT @@bulk_insert_buffer_size/1024/1024;
+---------------------------------------+
| @@bulk_insert_buffer_size/1024/1024 |
|---------------------------------------|
| 8.00000000 |
+---------------------------------------+
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
innodb_buffer_pool_size = 4000M
innodb_buffer_pool_instances = 4
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_write_io_threads=8
bulk_insert_buffer_size=128M
service mysql restart
SELECT @@bulk_insert_buffer_size/1024/1024;
+---------------------------------------+
| @@bulk_insert_buffer_size/1024/1024 |
|---------------------------------------|
| 128.00000000 |
+---------------------------------------+
mysqlslap
mysqlslap -uroot -pjuventus --engine=innodb --auto-generate-sql --auto-generate-sql-unique-query-number=100 --auto-generate-sql-unique-write-number=100 --auto-generate-sql-write-number=1000 --auto-generate-sql-load-type=mixed --concurrency=10,100 --number-of-queries=1000 --iterations=1 --number-char-cols=1 --number-int-cols=8 --auto-generate-sql-secondary-indexes=1 --verbose
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.842 seconds
Minimum number of seconds to run all queries: 0.842 seconds
Maximum number of seconds to run all queries: 0.842 seconds
Number of clients running queries: 10
Average number of queries per client: 100
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.875 seconds
Minimum number of seconds to run all queries: 0.875 seconds
Maximum number of seconds to run all queries: 0.875 seconds
Number of clients running queries: 100
Average number of queries per client: 10
sysbench
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
--table_size=100000 \
prepare
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_read_write.lua \
--tables=10 \
--table_size=100000 \
--time=60 \
--report-interval=10 \
--threads=5 \
run
Initializing worker threads...
Threads started!
[ 10s ] thds: 5 tps: 738.57 qps: 14776.13 (r/w/o: 10344.23/2954.27/1477.63) lat (ms,95%): 10.84 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 5 tps: 844.60 qps: 16894.45 (r/w/o: 11826.53/3378.71/1689.20) lat (ms,95%): 9.73 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 5 tps: 848.00 qps: 16960.43 (r/w/o: 11872.15/3392.29/1695.99) lat (ms,95%): 9.39 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 5 tps: 853.78 qps: 17073.65 (r/w/o: 11951.56/3414.53/1707.57) lat (ms,95%): 9.73 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 5 tps: 843.71 qps: 16875.18 (r/w/o: 11812.10/3375.66/1687.43) lat (ms,95%): 9.56 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 5 tps: 857.41 qps: 17149.44 (r/w/o: 12005.20/3429.33/1714.91) lat (ms,95%): 9.06 err/s: 0.10 reconn/s: 0.00
SQL statistics:
queries performed:
read: 698152
write: 199470
other: 99735
total: 997357
transactions: 49867 (830.96 per sec.)
queries: 997357 (16619.57 per sec.)
ignored errors: 1 (0.02 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0094s
total number of events: 49867
Latency (ms):
min: 1.76
avg: 6.01
max: 194.45
95th percentile: 9.73
sum: 299895.00
Threads fairness:
events (avg/stddev): 9973.4000/448.34
execution time (avg/stddev): 59.9790/0.01
sysbench --mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=juventus \
/usr/share/sysbench/oltp_common.lua \
--tables=10 \
cleanup
配置bulk_insert_buffer_size=128M对性能无明显提升
参考
数据库性能测试:sysbench用法详解
MySQL InnoDB performance improvement: InnoDB buffer pool instances – Updated!
MySQL性能调优 – 你必须了解的15个重要变量
MySQL 5.7 优化InnoDB配置
MySQL Performance: The Road to 500K QPS with MySQL 5.7
mysql默认配置修改