Mysql 数据库压力测试
<p>[TOC]</p>
<h2><center>sysbench数据库压力测试工具使用文档</center></h2>
<h5>1.构造测试表和测试数据</h5>
<p>命令示例:</p>
<pre><code class="language-shell">sysbench --db-driver=mysql --time=30 --threads=50 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=5 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare</code></pre>
<p>参数解释:
–db-driver=mysql:基于mysql的驱动去连接mysql数据库,如果是oracle,或者sqlserver,那自然就是其他的数据库的驱动了
–time=30:这个就是说连续访问30秒
–threads=50:这个就是说用50个线程模拟并发访问
–report-interval=1:这个就是说每隔1秒输出一下压测情况
–mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user:这个是说连接到哪台机器的哪个端口上的MySQL库,他的用户名和密码是什么
–mysql-db=test_db --tables=5 --table_size=500000:这个是说在test_db这个库里,构造5个测试表,每个测试表里构造50万条测试数据
oltp_read_write:这个就是说,执行oltp数据库的读写测试
–db-ps-mode=disable:这个是禁止ps模式
prepare:意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建5个测试表,每个表里创建50万条测试数据。</p>
<h5>2.测试数据库的综合读写TPS</h5>
<p>示例:</p>
<pre><code class="language-shell">sysbench --db-driver=mysql --time=30 --threads=50 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=5 --table_size=500000 oltp_read_write --db-ps-mode=disable run</code></pre>
<p>oltp_write_only:测试写入性能
oltp_read_write : 测试读写性能
oltp_read_only:测试只读性能
oltp_delete:测试删除性能
oltp_update_index: 测试更新索引字段性能
oltp_update_non_index: 测试更新非索引字段性能
oltp_insert: 测试插入性能</p>
<h5>3.测试结果说明</h5>
<pre><code class="language-shell">[ 17s ] thds: 50 tps: 713.31 qps: 14112.15 (r/w/o: 9905.32/2782.21/1424.62) lat (ms,95%): 173.58 err/s: 0.00 reconn/s: 0.00</code></pre>
<p>thds: 50,有50个线程在压测
tps: 713.31,每秒执行了713.31个事务
qps: 14112.15,每秒可以执行14112.15个请求
(r/w/o: 9905.32/2782.21/1424.62),意思是在每秒9905.32个请求中,有2782.21个请求是读请求,1424.62个请求是写请求,剩下的是其他的请求
lat (ms, 95%):173.58,意思是95%的请求的延迟都在173.58毫秒以下
err/s: 0.00 reconn/s: 0.00,这两个的意思是每秒有0个请求是失败的,发生了0次网络重连</p>
<h5>4.总结报告</h5>
<pre><code class="language-shell">SQL statistics:
queries performed:
read: 273602
write: 78172
other: 39086
total: 390860
transactions: 19543 (650.89 per sec.)
queries: 390860 (13017.74 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 30.0240s
total number of events: 19543
Latency (ms):
min: 3.80
avg: 76.77
max: 710.73
95th percentile: 262.64
sum: 1500310.20
Threads fairness:
events (avg/stddev): 390.8600/10.25
execution time (avg/stddev): 30.0062/0.01
</code></pre>
<p>read: 273602 的意思是在30s的压测期间执行了27万多次的读请求
write: 78172 的意思在压测期间执行了差不多8万次的写请求
other: 39086 的意思是在压测期间执行了差不多4万次的其他请求
total: 390860 的意思是一共执行了39万多次的请求
transactions: 19543 ( 650.89 per sec. ) 的意思是一共执行了差不多2万万个事务,每秒执行650.89多个事务
queries: 390860 (13017.74 per sec. ) 的意思是一共执行了39万多次的请求,每秒执行1万3千多请求
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
// 下面就是说,一共执行了30s的压测,执行了差不多两万的事务
General staticstics:
total time: 30.0240s
total number of events: 19543
Latency (ms):
min: 3.80 意思是请求中延迟最小的是3.80ms
avg: 76.77 意思是所有请求平均延迟是76.77ms
max: 710.73 意思是延迟最大的请求是710.73ms
95th percentile: 262.64 意思是95%的请求延迟都在262.64 ms以内</p>
<h5>5.其他</h5>
<p>top 查看CPU使用情况
free 查看内存使用情况</p>