searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

Sysbench测试工具介绍及其在PG中的应用

2023-09-27 07:57:02
11
0

1.简介

Sysbench是一个模块化的、跨平台的基准测试工具,主要用于评估计算机系统的性能。它可以测试CPU、内存、磁盘、文件IO等方面的性能,并且支持多种数据库的基准测试。它基于C语言实现,通过调用自带lua脚本或用户自制脚本进行测试。

 

2.系统性能测试

CPU测试

# 测试CPU性能
# 生成一个质数表,然后对这个表进行一些简单的计算,以测试CPU的性能。--cpu-max-prime参数指定了生成质数表的最大值
sysbench cpu --cpu-max-prime=20000 run
# 结果:
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Prime numbers limit: 1000
Initializing worker threads...
Threads started!

CPU speed:
    events per second: 23679.13

General statistics:
    total time:                          10.0001s
    total number of events:              236836

Latency (ms):
         min:                                  0.04
         avg:                                  0.04
         max:                                  0.13
         95th percentile:                      0.05
         sum:                               9959.51

Threads fairness:
    events (avg/stddev):           236836.0000/0.00
    execution time (avg/stddev):   9.9595/0.00
 

内存测试

# 测试内存性能
# 分配10MB的内存,然后对这个内存进行一些简单的读写操作,以测试内存的性能。--memory-block-size参数指定了每个内存块的大小,可以根据需要进行调整。--memory-total-size参数指定了总共要分配的内存大小
sysbench memory --memory-block-size=1K --memory-total-size=10M run
# 结果:
Running memory speed test with the following options:
  block size: 1KiB
  total size: 10MiB
  operation: write
  scope: global
​
Initializing worker threads...
Threads started!
Total operations: 10240 (2178730.36 per second)
10.00 MiB transferred (2127.67 MiB/sec)
​
General statistics:
    total time:                          0.0029s
    total number of events:              10240
​
Latency (ms):
         min:                                  0.00
         avg:                                  0.00
         max:                                  0.01
         95th percentile:                      0.00
         sum:                                  1.09
​
Threads fairness:
    events (avg/stddev):           10240.0000/0.00
    execution time (avg/stddev):   0.0011/0.00

磁盘测试

# 测试磁盘的性能 与数据库测试三步骤类似
# 在磁盘上创建一个10MB的文件,然后对这个文件进行随机读写操作,以测试磁盘的性能。--file-total-size参数指定了要创建的文件大小,--file-test-mode参数指定了测试模式(seqread、seqwrite、seqrewrit、rndread、rndwrite、rndrw)
sysbench fileio --file-total-size=10M --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=10M --file-test-mode=rndrw run

##执行结果
Creating file test_file.127
10485760 bytes written in 30.89 seconds (0.32 MiB/sec).
​
Extra file open flags: 0
128 files, 80KiB each
10MiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
​
Threads started!
​
​
File operations:
    reads/s:                      17.91
    writes/s:                     11.94
    fsyncs/s:                     29.26
​
Throughput:
    read, MiB/s:                  0.28
    written, MiB/s:               0.19
​
General statistics:
    total time:                          10.0470s
    total number of events:              594
​
Latency (ms):
         min:                                  0.00
         avg:                                 16.91
         max:                                706.18
         95th percentile:                    139.85
         sum:                              10045.77
​
Threads fairness:
    events (avg/stddev):           594.0000/0.00
    execution time (avg/stddev):   10.0458/0.00
​
sysbench fileio --file-total-size=10M --file-test-mode=rndrw cleanup

3.数据库测试

测试三个步骤

1. prepare(装载数据到数据库)

2. run(运行事务)

3. cleanup(删压测的数据表)

测试模式

模式名 说明
oltp_read_only 测试数据库的只读性能
oltp_delete 测试数据库的删除性能
oltp_update_index 测试数据库的更新索引字段的性能
oltp_update_non_index 测试数据库的更新非索引字段的性能
oltp_insert 测试数据库的插入性能
oltp_write_only 测试数据库的只写性能
oltp_read_write 测试数据库的综合读写TPS

测试相关参数

参数 说明 默认值/填写例子
db-driver 数据库引擎。 pgsql
pgsql-host PostgreSQL实例连接地址。 逻辑ip
pgsql-port PostgreSQL实例连接端口。 postgres连接端口
pgsql-user PostgreSQL实例用户账号。 postgres连接用户
pgsql-password PostgreSQL实例用户账号对应的密码。 postgres连接密码
pgsql-db PostgreSQL实例数据库名。 postgres连接数据库名
time 压测时间间隔。 180-300s
threads 测试并发线程数。 100,300,500
tables 表的数目 1
table-size 每个表的记录行数 10000
max-requests 压力请求数量,取值为0,表示不限请求数量,单位为单次Lua场景请求数。 events的数目,0
report-interval 压测报告输出周期,单位为秒。 5s
force-shutdown 是否强制终止测试。 1

测试流程实践

# 装载数据到数据库
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
prepare

# 执行测试
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
run

# 清除测试数据
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword  \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
cleanup

测试结果解读

# 运行中的测试数据
​
Initializing worker threads...
​
Threads started!
# 95%的请求的延迟都在2045毫秒以下
[ 5s ] thds: 64 tps: 60.39 qps: 1535.69 (r/w/o: 1116.14/258.31/161.24) lat (ms,95%): 2045.74 err/s: 6.58 reconn/s: 0.00
[ 10s ] thds: 64 tps: 49.40 qps: 1135.09 (r/w/o: 809.27/201.02/124.81) lat (ms,95%): 4203.93 err/s: 8.40 reconn/s: 0.00
[ 15s ] thds: 64 tps: 33.00 qps: 748.21 (r/w/o: 532.00/133.20/83.00) lat (ms,95%): 5124.81 err/s: 5.00 reconn/s: 0.00
…………
[ 60s ] thds: 64 tps: 23.00 qps: 511.00 (r/w/o: 361.20/93.80/56.00) lat (ms,95%): 11523.48 err/s: 2.80 reconn/s: 0.00
​
# 运行完毕结果
SQL statistics:
    queries performed:
        read:                            28826
        write:                           7279
        other:                           4508 -- 其他操作 SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等
        total:                           40613
    transactions:                        1816   (28.29 per sec.)  -- 总事务数 (每秒事务数tps)
    queries:                             40613  (632.59 per sec.) -- 总操作数 包括读写和其他(每秒操作数qps)
    ignored errors:                      243    (3.78 per sec.)   -- 错误次数
    reconnects:                          0      (0.00 per sec.)   -- 重连次数
​
General statistics:
    total time:                          64.1994s               -- 运行时间
    total number of events:              1816                   -- 总的事务数
​
Latency (ms):
         min:                                 58.28             -- 最小耗时
         avg:                               2199.28             -- 平均耗时
         max:                              27182.91             -- 平均耗时
         95th percentile:                   7895.16             -- 超过95%平均耗时
         sum:                            3993890.07             -- 总耗时
​
Threads fairness:
    events (avg/stddev):           28.3750/5.81             -- 线程公平性统计信息,表示负载的公平性
    execution time (avg/stddev):   62.4045/1.14             -- 线程执行时间为62.4s, 执行平均次数为28次,标准差为5.81

0条评论
0 / 1000
g****n
4文章数
1粉丝数
g****n
4 文章 | 1 粉丝
原创

Sysbench测试工具介绍及其在PG中的应用

2023-09-27 07:57:02
11
0

1.简介

Sysbench是一个模块化的、跨平台的基准测试工具,主要用于评估计算机系统的性能。它可以测试CPU、内存、磁盘、文件IO等方面的性能,并且支持多种数据库的基准测试。它基于C语言实现,通过调用自带lua脚本或用户自制脚本进行测试。

 

2.系统性能测试

CPU测试

# 测试CPU性能
# 生成一个质数表,然后对这个表进行一些简单的计算,以测试CPU的性能。--cpu-max-prime参数指定了生成质数表的最大值
sysbench cpu --cpu-max-prime=20000 run
# 结果:
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Prime numbers limit: 1000
Initializing worker threads...
Threads started!

CPU speed:
    events per second: 23679.13

General statistics:
    total time:                          10.0001s
    total number of events:              236836

Latency (ms):
         min:                                  0.04
         avg:                                  0.04
         max:                                  0.13
         95th percentile:                      0.05
         sum:                               9959.51

Threads fairness:
    events (avg/stddev):           236836.0000/0.00
    execution time (avg/stddev):   9.9595/0.00
 

内存测试

# 测试内存性能
# 分配10MB的内存,然后对这个内存进行一些简单的读写操作,以测试内存的性能。--memory-block-size参数指定了每个内存块的大小,可以根据需要进行调整。--memory-total-size参数指定了总共要分配的内存大小
sysbench memory --memory-block-size=1K --memory-total-size=10M run
# 结果:
Running memory speed test with the following options:
  block size: 1KiB
  total size: 10MiB
  operation: write
  scope: global
​
Initializing worker threads...
Threads started!
Total operations: 10240 (2178730.36 per second)
10.00 MiB transferred (2127.67 MiB/sec)
​
General statistics:
    total time:                          0.0029s
    total number of events:              10240
​
Latency (ms):
         min:                                  0.00
         avg:                                  0.00
         max:                                  0.01
         95th percentile:                      0.00
         sum:                                  1.09
​
Threads fairness:
    events (avg/stddev):           10240.0000/0.00
    execution time (avg/stddev):   0.0011/0.00

磁盘测试

# 测试磁盘的性能 与数据库测试三步骤类似
# 在磁盘上创建一个10MB的文件,然后对这个文件进行随机读写操作,以测试磁盘的性能。--file-total-size参数指定了要创建的文件大小,--file-test-mode参数指定了测试模式(seqread、seqwrite、seqrewrit、rndread、rndwrite、rndrw)
sysbench fileio --file-total-size=10M --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=10M --file-test-mode=rndrw run

##执行结果
Creating file test_file.127
10485760 bytes written in 30.89 seconds (0.32 MiB/sec).
​
Extra file open flags: 0
128 files, 80KiB each
10MiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
​
Threads started!
​
​
File operations:
    reads/s:                      17.91
    writes/s:                     11.94
    fsyncs/s:                     29.26
​
Throughput:
    read, MiB/s:                  0.28
    written, MiB/s:               0.19
​
General statistics:
    total time:                          10.0470s
    total number of events:              594
​
Latency (ms):
         min:                                  0.00
         avg:                                 16.91
         max:                                706.18
         95th percentile:                    139.85
         sum:                              10045.77
​
Threads fairness:
    events (avg/stddev):           594.0000/0.00
    execution time (avg/stddev):   10.0458/0.00
​
sysbench fileio --file-total-size=10M --file-test-mode=rndrw cleanup

3.数据库测试

测试三个步骤

1. prepare(装载数据到数据库)

2. run(运行事务)

3. cleanup(删压测的数据表)

测试模式

模式名 说明
oltp_read_only 测试数据库的只读性能
oltp_delete 测试数据库的删除性能
oltp_update_index 测试数据库的更新索引字段的性能
oltp_update_non_index 测试数据库的更新非索引字段的性能
oltp_insert 测试数据库的插入性能
oltp_write_only 测试数据库的只写性能
oltp_read_write 测试数据库的综合读写TPS

测试相关参数

参数 说明 默认值/填写例子
db-driver 数据库引擎。 pgsql
pgsql-host PostgreSQL实例连接地址。 逻辑ip
pgsql-port PostgreSQL实例连接端口。 postgres连接端口
pgsql-user PostgreSQL实例用户账号。 postgres连接用户
pgsql-password PostgreSQL实例用户账号对应的密码。 postgres连接密码
pgsql-db PostgreSQL实例数据库名。 postgres连接数据库名
time 压测时间间隔。 180-300s
threads 测试并发线程数。 100,300,500
tables 表的数目 1
table-size 每个表的记录行数 10000
max-requests 压力请求数量,取值为0,表示不限请求数量,单位为单次Lua场景请求数。 events的数目,0
report-interval 压测报告输出周期,单位为秒。 5s
force-shutdown 是否强制终止测试。 1

测试流程实践

# 装载数据到数据库
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
prepare

# 执行测试
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
run

# 清除测试数据
sysbench oltp_read_write \
--db-driver=pgsql \
--pgsql-db=YourDB \
--pgsql-user=YourUser \
--pgsql-password=YourPassword  \
--pgsql-port=666x --pgsql-host=192.168.x.x \
--tables=64 \
--table-size=100 \
--time=60 \
--max-requests=0 \
--threads=64 \
--report-interval=5 \
cleanup

测试结果解读

# 运行中的测试数据
​
Initializing worker threads...
​
Threads started!
# 95%的请求的延迟都在2045毫秒以下
[ 5s ] thds: 64 tps: 60.39 qps: 1535.69 (r/w/o: 1116.14/258.31/161.24) lat (ms,95%): 2045.74 err/s: 6.58 reconn/s: 0.00
[ 10s ] thds: 64 tps: 49.40 qps: 1135.09 (r/w/o: 809.27/201.02/124.81) lat (ms,95%): 4203.93 err/s: 8.40 reconn/s: 0.00
[ 15s ] thds: 64 tps: 33.00 qps: 748.21 (r/w/o: 532.00/133.20/83.00) lat (ms,95%): 5124.81 err/s: 5.00 reconn/s: 0.00
…………
[ 60s ] thds: 64 tps: 23.00 qps: 511.00 (r/w/o: 361.20/93.80/56.00) lat (ms,95%): 11523.48 err/s: 2.80 reconn/s: 0.00
​
# 运行完毕结果
SQL statistics:
    queries performed:
        read:                            28826
        write:                           7279
        other:                           4508 -- 其他操作 SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等
        total:                           40613
    transactions:                        1816   (28.29 per sec.)  -- 总事务数 (每秒事务数tps)
    queries:                             40613  (632.59 per sec.) -- 总操作数 包括读写和其他(每秒操作数qps)
    ignored errors:                      243    (3.78 per sec.)   -- 错误次数
    reconnects:                          0      (0.00 per sec.)   -- 重连次数
​
General statistics:
    total time:                          64.1994s               -- 运行时间
    total number of events:              1816                   -- 总的事务数
​
Latency (ms):
         min:                                 58.28             -- 最小耗时
         avg:                               2199.28             -- 平均耗时
         max:                              27182.91             -- 平均耗时
         95th percentile:                   7895.16             -- 超过95%平均耗时
         sum:                            3993890.07             -- 总耗时
​
Threads fairness:
    events (avg/stddev):           28.3750/5.81             -- 线程公平性统计信息,表示负载的公平性
    execution time (avg/stddev):   62.4045/1.14             -- 线程执行时间为62.4s, 执行平均次数为28次,标准差为5.81

文章来自个人专栏
pg数据库探索
3 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
1
0