索菲 發表於 2023-8-25 00:00:00

SysBench系统性能基准测试工具

<p>一. 简介<br>
SysBench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。<br>
当前功能允许测试的系统参数有:<br>
file I/O performance (文件I / O性能)<br>
scheduler performance (调度性能)<br>
memory allocation and transfer speed (内存分配和传输速度)<br>
POSIX threads implementation performance (POSIX线程执行绩效)<br>
database server performance (OLTP benchmark) (数据库服务器性能)<br>
SysBench运行指定数目的线程,他们都是并行的执行请求。实际工作量的请求产生依赖于指定的测试模式(在编译中添加测试模块)。可以限制请求总数或总时间为基准,或两者。</p>
<p>二. 安装<br>
下载地址:<br>
# wget http://nchc.dl.sourceforge.net/project/sysbench/sysbench/0.4.12/sysbench-0.4.12.tar.gz<br>
# tar zxvf sysbench-0.4.12.tar.gz -C ../software/<br>
# ./configure --prefix=/usr/local/sysbench-0.4.12 \<br>
--with-mysql-includes=/usr/local/mysql-5.5.8/include \<br>
--with-mysql-libs=/usr/local/mysql-5.5.8/lib<br>
# make<br>
# make install</p>
<p>安装过程中出现的错误以及解决办法:<br>
问题一:<br>
../libtool: line 838: X--tag=CC: command not found<br>
../libtool: line 871: libtool: ignoring unknown tag : command not found<br>
../libtool: line 838: X--mode=link: command not found<br>
../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found<br>
../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found<br>
../libtool: line 2231: X-g: command not found<br>
../libtool: line 2231: X-O2: command not found<br>
../libtool: line 1951: X-L/usr/local/mysql-5.5.8/lib: No such file or directory<br>
../libtool: line 2400: Xsysbench: command not found<br>
解决办法:<br>
1.在编译前先运行autogen.sh即可。<br>
2.安装新版本的libtool工具。</p>
<p>问题二:<br>
./sysbench: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory<br>
解决办法:<br>
# ln -s /usr/local/mysql-5.5.8/lib/libmysqlclient.so.16 /lib64/libmysqlclient.so.16</p>
<p>三. 测试选项说明<br>
# ./sysbench<br>
测试用例:<br>
sysbench ... --test=&lt;test-name&gt; ... command</p>
<p>通用选项:<br>
--num-threads=N 创建测试线程的数目。默认为1.<br>
--max-requests=N 请求的最大数目。默认为10000,0代表不限制。<br>
--max-time=N 最大执行时间,单位是s。默认是0,不限制。<br>
--forced-shutdown=STRING 超过max-time强制中断。默认是off。]<br>
--thread-stack-size=SIZE 每个线程的堆栈大小。默认是32K。<br>
--init-rng= 在测试开始时是否初始化随机数发生器。默认是off。<br>
--test=STRING 指定测试项目名称。<br>
--debug= 是否显示更多的调试信息。默认是off。<br>
--validate= 在可能情况下执行验证检查。默认是off。</p>
<p>测试项目:<br>
fileio - File I/O test<br>
cpu - CPU performance test<br>
memory - Memory functions speed test<br>
threads - Threads subsystem performance test<br>
mutex - Mutex performance test(互斥性能测试)<br>
oltp - OLTP test</p>
<p>指令: prepare(测试前准备工作) run(正式测试) cleanup(测试后删掉测试数据) help version</p>
<p>See 'sysbench --test=&lt;name&gt; help' for a list of options for each test. 查看每个测试项目的更多选项列表。</p>
<p># ./sysbench --test=fileio help<br>
--file-num=N 创建测试文件的数量。默认是128<br>
--file-block-size=N 测试时文件块的大小。默认是16384(16K)<br>
--file-total-size=SIZE 测试文件的总大小。默认是2G<br>
--file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}<br>
--file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync<br>
--file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空<br>
--file-fsync-freq=N 执行fsync()的频率。(0 – 不使用fsync())。默认是100<br>
--file-fsync-all= 每执行完一次写操作就执行一次fsync。默认是off<br>
--file-fsync-end= 在测试结束时才执行fsync。默认是on<br>
--file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync<br>
--file-merged-requests=N 如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0<br>
--file-rw-ratio=N 测试时的读写比例。默认是1.5</p>
<p># ./sysbench --test=cpu help<br>
--cpu-max-prime=N 最大质数发生器数量。默认是10000</p>
<p># ./sysbench --test=memory help<br>
--memory-block-size=SIZE 测试时内存块大小。默认是1K<br>
--memory-total-size=SIZE 传输数据的总大小。默认是100G<br>
--memory-scope=STRING 内存访问范围{global,local}。默认是global<br>
--memory-hugetlb= 从HugeTLB池内存分配。默认是off<br>
--memory-oper=STRING 内存操作类型。{read, write, none} 默认是write<br>
--memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq</p>
<p># ./sysbench --test=threads help<br>
--thread-yields=N 每个请求产生多少个线程。默认是1000<br>
--thread-locks=N 每个线程的锁的数量。默认是8</p>
<p># ./sysbench --test=mutex help<br>
--mutex-num=N 数组互斥的总大小。默认是4096<br>
--mutex-locks=N 每个线程互斥锁的数量。默认是50000<br>
--mutex-loops=N 内部互斥锁的空循环数量。默认是10000</p>
<p># ./sysbench --test=oltp help<br>
oltp options:<br>
--oltp-test-mode=STRING 执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex<br>
--oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session<br>
--oltp-sp-name=STRING 存储过程的名称。默认为空<br>
--oltp-read-only= 只读模式。Update,delete,insert语句不可执行。默认是off<br>
--oltp-skip-trx= 省略begin/commit语句。默认是off<br>
--oltp-range-size=N 查询范围。默认是100<br>
--oltp-point-selects=N number of point selects <br>
--oltp-simple-ranges=N number of simple ranges <br>
--oltp-sum-ranges=N number of sum ranges <br>
--oltp-order-ranges=N number of ordered ranges <br>
--oltp-distinct-ranges=N number of distinct ranges <br>
--oltp-index-updates=N number of index update <br>
--oltp-non-index-updates=N number of non-index updates <br>
--oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} <br>
--oltp-auto-inc= AUTO_INCREMENT是否开启。默认是on<br>
--oltp-connect-delay=N 在多少微秒后连接数据库。默认是10000<br>
--oltp-user-delay-min=N 每个请求最短等待时间。单位是ms。默认是0<br>
--oltp-user-delay-max=N 每个请求最长等待时间。单位是ms。默认是0<br>
--oltp-table-name=STRING 测试时使用到的表名。默认是sbtest<br>
--oltp-table-size=N 测试表的记录数。默认是10000<br>
--oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special<br>
--oltp-dist-iter=N 产生数的迭代次数。默认是12<br>
--oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是1<br>
--oltp-dist-res=N ‘special’的百分比值。默认是75</p>
<p>General database options:<br>
--db-driver=STRING 指定数据库驱动程序('help' to get list of available drivers)<br>
--db-ps-mode=STRING编制报表使用模式{auto, disable} </p>
<p>Compiled-in database drivers:<br>
mysql - MySQL driver</p>
<p>mysql options:<br>
--mysql-host= MySQL server host <br>
--mysql-port=N MySQL server port <br>
--mysql-socket=STRING MySQL socket<br>
--mysql-user=STRING MySQL user <br>
--mysql-password=STRING MySQL password []<br>
--mysql-db=STRING MySQL database name <br>
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} <br>
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} <br>
--mysql-ssl= use SSL connections, if available in the client library <br>
--myisam-max-rows=N max-rows parameter for MyISAM tables <br>
--mysql-create-options=STRING additional options passed to CREATE TABLE []</p>
<p>四. 测试实例<br>
1.测试cpu<br>
# ./sysbench --test=cpu --cpu-max-prime=20000 run<br>
Number of threads: 1</p>
<p>Doing CPU performance benchmark</p>
<p>Threads started!<br>
Done.</p>
<p>Maximum prime number checked in CPU test: 20000<br>
Test execution summary:<br>
total time: 31.9364s<br>
total number of events: 10000<br>
total time taken by event execution: 31.9334<br>
per-request statistics:<br>
min: 3.18ms<br>
avg: 3.19ms<br>
max: 3.60ms<br>
approx. 95 percentile: 3.20ms</p>
<p>Threads fairness:<br>
events (avg/stddev): 10000.0000/0.00<br>
execution time (avg/stddev): 31.9334/0.00</p>
<p>2.测试线程<br>
# ./sysbench --num-threads=64 --test=threads --thread-yields=100 --thread-locks=2 run<br>
Number of threads: 64</p>
<p>Doing thread subsystem performance test<br>
Thread yields per test: 100 Locks used: 2<br>
Threads started!<br>
Done.<br>
Test execution summary:<br>
total time: 2.2507s<br>
total number of events: 10000<br>
total time taken by event execution: 143.8405<br>
per-request statistics:<br>
min: 0.03ms<br>
avg: 14.38ms<br>
max: 411.39ms<br>
approx. 95 percentile: 63.49ms</p>
<p>Threads fairness:<br>
events (avg/stddev): 156.2500/45.17<br>
execution time (avg/stddev): 2.2475/0.00</p>
<p>3.测试mutex<br>
# ./sysbench --num-threads=1500 --max-requests=2000 --test=mutex --mutex-num=10240 --mutex-locks=100000 --mutex-loops=15000 run<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>Running the test with following options:<br>
Number of threads: 1500</p>
<p>Doing mutex performance test<br>
Threads started!<br>
Done.<br>
Test execution summary:<br>
total time: 74.0710s<br>
total number of events: 1500<br>
total time taken by event execution: 5410.6925<br>
per-request statistics:<br>
min: 485.77ms<br>
avg: 3607.13ms<br>
max: 13770.44ms<br>
approx. 95 percentile: 12489.67ms</p>
<p>Threads fairness:<br>
events (avg/stddev): 1.0000/0.00<br>
execution time (avg/stddev): 3.6071/3.97</p>
<p>4.测试fileio<br>
# ./sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>128 files, 24576Kb each, 3072Mb total<br>
Creating files for the test...</p>
<p># ./sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw run<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>Running the test with following options:<br>
Number of threads: 16</p>
<p>Extra file open flags: 0<br>
128 files, 24Mb each<br>
3Gb total file size<br>
Block size 16Kb<br>
Number of random requests for random IO: 10000<br>
Read/Write ratio for combined random IO test: 1.50<br>
Periodic FSYNC enabled, calling fsync() each 100 requests.<br>
Calling fsync() at the end of test, Enabled.<br>
Using synchronous I/O mode<br>
Doing random r/w test<br>
Threads started!<br>
Done.</p>
<p>Operations performed: 6011 Read, 3997 Write, 12692 Other = 22700 Total<br>
Read 93.922Mb Written 62.453Mb Total transferred 156.38Mb (9.9885Mb/sec)<br>
639.27 Requests/sec executed</p>
<p>Test execution summary:<br>
total time: 15.6555s<br>
total number of events: 10008<br>
total time taken by event execution: 34.5359<br>
per-request statistics:<br>
min: 0.01ms<br>
avg: 3.45ms<br>
max: 828.73ms<br>
approx. 95 percentile: 0.07ms</p>
<p>Threads fairness:<br>
events (avg/stddev): 625.5000/137.06<br>
execution time (avg/stddev): 2.1585/0.49</p>
<p># ./sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw cleanup<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>Removing test files...</p>
<p>5.OLTP测试<br>
# ./sysbench --test=oltp --mysql-table-engine=innodb --mysql-port=3307 --mysql-db=test --oltp-table-size=10000000 --mysql-socket=/tmp/mysql-5.5.8.sock prepare<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>No DB drivers specified, using mysql<br>
Creating table 'sbtest'...<br>
Creating 10000000 records in table 'sbtest'...</p>
<p># ./sysbench --num-threads=100 --max-requests=100000 --test=oltp --oltp-table-size=1000000 --mysql-port=3307 --mysql-db=test --mysql-socket=/tmp/mysql-5.5.8.sock run<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>No DB drivers specified, using mysql<br>
Running the test with following options:<br>
Number of threads: 100</p>
<p>Doing OLTP test.<br>
Running mixed OLTP test<br>
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)<br>
Using "BEGIN" for starting transactions<br>
Using auto_inc on the id column<br>
Maximum number of requests for OLTP test is limited to 100000<br>
Threads started!<br>
Done.</p>
<p>OLTP test statistics:<br>
queries performed:<br>
read: 1400154<br>
write: 500055<br>
other: 200022<br>
total: 2100231<br>
transactions: 100011 (740.18 per sec.)<br>
deadlocks: 0 (0.00 per sec.)<br>
read/write requests: 1900209 (14063.46 per sec.)<br>
other operations: 200022 (1480.36 per sec.)</p>
<p>Test execution summary:<br>
total time: 135.1168s<br>
total number of events: 100011<br>
total time taken by event execution: 13504.7609<br>
per-request statistics:<br>
min: 2.70ms<br>
avg: 135.03ms<br>
max: 2319.30ms<br>
approx. 95 percentile: 224.40ms</p>
<p>Threads fairness:<br>
events (avg/stddev): 1000.1100/12.06<br>
execution time (avg/stddev): 135.0476/0.04</p>
<p># ./sysbench --test=oltp --mysql-table-engine=innodb --mysql-port=3307 --mysql-db=test --oltp-table-size=10000000 --mysql-socket=/tmp/mysql-5.5.8.sock cleanup<br>
sysbench 0.4.12: multi-threaded system evaluation benchmark</p>
<p>No DB drivers specified, using mysql<br>
Dropping table 'sbtest'...<br>
Done.</p>
頁: [1]
查看完整版本: SysBench系统性能基准测试工具