准备创建表和数据:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
测试数据库的只读性能,使用的是oltp_read_only模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_read_only --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 25242
write: 0
other: 3606
total: 28848
transactions: 1803 (859.40 per sec.)
queries: 28848 (13750.37 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 2.0931s
total number of events: 1803
Latency (ms):
min: 204.65
avg: 865.57
max: 1312.73
95th percentile: 1191.92
sum: 1560630.86
测试数据库的删除性能,使用的是oltp_delete模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_delete --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 0
write: 11506
other: 9290
total: 20796
transactions: 20796 (16813.13 per sec.)
queries: 20796 (16813.13 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.2349s
total number of events: 20796
Latency (ms):
min: 3.16
avg: 51.30
max: 255.24
95th percentile: 58.92
sum: 1066896.74
测试数据库的更新索引字段的性能,使用的是oltp_update_index模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_update_index --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 0
write: 17355
other: 0
total: 17355
transactions: 17355 (14499.51 per sec.)
queries: 17355 (14499.51 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.1948s
total number of events: 17355
Latency (ms):
min: 5.27
avg: 61.99
max: 244.16
95th percentile: 75.82
sum: 1075762.57
测试数据库的更新非索引字段的性能,使用的是oltp_update_non_index模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_update_non_index --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 0
write: 17801
other: 0
total: 17801
transactions: 17801 (14435.25 per sec.)
queries: 17801 (14435.25 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.2312s
total number of events: 17801
Latency (ms):
min: 13.85
avg: 60.14
max: 261.74
95th percentile: 82.96
sum: 1070611.81
测试数据库的插入性能,使用的是oltp_insert模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_insert --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 0
write: 19685
other: 0
total: 19685
transactions: 19685 (16335.50 per sec.)
queries: 19685 (16335.50 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.2000s
total number of events: 19685
Latency (ms):
min: 4.49
avg: 52.90
max: 228.04
95th percentile: 77.19
sum: 1041424.34
测试数据库的写入性能,使用的是oltp_write_only模式:
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_write_only --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 0
write: 17940
other: 9112
total: 27052
transactions: 4480 (3374.72 per sec.)
queries: 27052 (20377.87 per sec.)
ignored errors: 43 (32.39 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.3226s
total number of events: 4480
Latency (ms):
min: 65.01
avg: 248.24
max: 702.04
95th percentile: 314.45
sum: 1112124.54
测试数据库的综合读写TPS,使用的是oltp_read_write模式
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_read_write --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 25004
write: 7114
other: 3588
total: 35706
transactions: 1779 (899.49 per sec.)
queries: 35706 (18053.45 per sec.)
ignored errors: 7 (3.54 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.9728s
total number of events: 1779
Latency (ms):
min: 199.06
avg: 854.98
max: 1804.89
95th percentile: 1191.92
sum: 1521010.69
测试数据库的综合读写TPS,使用的是oltp_read_write模式:
sysbench --db-driver=pgsql --time=1 --threads=500 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_read_write --db-ps-mode=disable run
SQL statistics:
queries performed:
read: 11704
write: 3333
other: 1677
total: 16714
transactions: 833 (601.84 per sec.)
queries: 16714 (12075.74 per sec.)
ignored errors: 3 (2.17 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 1.3792s
total number of events: 833
Latency (ms):
min: 293.30
avg: 731.76
max: 1353.39
95th percentile: 1170.65
sum: 609554.21
使用上面的命令,sysbench工具会根据你的指令构造出各种各样的SQL语句去更新或者查询1张测试表里的数据,同时监测出数据库的压测性能指标,最后完成压测之后,可以执行下面的cleanup命令,清理数据。
sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgsql-password=123456 --pgsql-db=test_db --tables=1 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup
文章参考:
https://www.cnblogs.com/ariesblog/p/13847740.html
https://blog.csdn.net/weixin_39327527/article/details/107528485
版权声明:本文为qq_36805343原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。