ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
安装、使用、测试 sysbench 下载地址: https://github.com/akopytov/sysbench/tree/0.5 进入解压目录,并且创建安装目录: [root@10-248-56-192 software]# unzip sysbench-0.5.zip [root@10-248-56-192 software]# cd sysbench-0.5 安装依赖包:yum -y install automake autoconf libtool 准备编译: ./autogen.sh 遇到报错: ~~~ [root@localhost sysbench-0.4.12.14]# ./autogen.sh ./autogen.sh: running `libtoolize --copy --force' libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'. libtoolize: copying file `config/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'. libtoolize: copying file `m4/libtool.m4' libtoolize: copying file `m4/ltoptions.m4' libtoolize: copying file `m4/ltsugar.m4' libtoolize: copying file `m4/ltversion.m4' libtoolize: copying file `m4/lt~obsolete.m4' ./autogen.sh: running `aclocal -I m4' ./autogen.sh: running `autoheader' ./autogen.sh: running `automake -c --foreign --add-missing' ./autogen.sh: running `autoconf' configure.ac:49: error: possibly undefined macro: AC_LIB_PREFIX If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. Can't execute autoconf ~~~ 查阅资料,解决方法; [root@localhost sysbench-0.4.12.14]# cat configure.ac | grep AC_LIB_PREFIX AC_LIB_PREFIX() 注释掉这个函数就可以了 ./configure ERROR: cannot find MySQL libraries. If you want to compile with MySQL support 没找到mysql库 需要用参数指定下 --with-mysql-includes和--with-mysql-libs `./configure --prefix=/usr/sysbench/ --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/lib64/ --with-mysql` 由于是yum安装的mysql,我也不知道路径在哪里。如何查找mysql的安装路径? 安装mysql-devel,才能使用mysql_config ~~~ #yum install -y mysql-devel #mysql_config -help Usage: /usr/bin/mysql_config-64 [OPTIONS] Options: --cflags [-I/usr/include/mysql -g -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --cxxflags [-I/usr/include/mysql -g -fexceptions -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --include [-I/usr/include/mysql] --libs [-L/usr/lib64/mysql -lmysqlclient -lpthread -lm -lrt -ldl] --libs_r [-L/usr/lib64/mysql -lmysqlclient -lpthread -lm -lrt -ldl] --plugindir [/usr/lib64/mysql/plugin] --socket [/var/lib/mysql/mysql.sock] --port [0] --version [5.6.39] --libmysqld-libs [-L/usr/lib64/mysql -lmysqld -lpthread -lm -lrt -lcrypt -ldl -laio -lnuma] --variable=VAR VAR is one of: pkgincludedir [/usr/include/mysql] pkglibdir [/usr/lib64/mysql] plugindir [/usr/lib64/mysql/plugin] ~~~ 报错: configure: error: cannot find MySQL client libraries in /usr/lib64/ 编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可 ln -s /usr/lib64/libmysqlclient.so.15.0.0 /usr/lib64/libmysqlclient_r.so 4、make && make install 5、此时在终端中输入sysbench命令会出现 -bash: sysbench: command not found 将编译的安装目录添加至环境变量: export PATH=$PATH:/usr/sysbench/bin source .bash_profile 6. 执行下命令: ~~~ #sysbench --help #sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory #问题原因:sysbench无法找到mysql的库文件,可能是环境变量LD_LIBRARY_PATH没有设置,设置后即可解决该问题: #export LD_LIBRARY_PATH=/alidata/server/mysql5.7/lib/lib #sysbench --version sysbench 1.0.12 (using bundled LuaJIT 2.1.0-beta2) ~~~ 查询sysbench是否正确安装 sysbench –v 开始测试 1、CPU测试  sysbench CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间 sysbench --test=cpu --cpu-max-prime=20000 run 输出如下: Maximum prime number checked in CPU test: 200000 Test execution summary: total time: 286.5703s total number of events: 10000 total time taken by event execution: 285197.4463 per-request statistics: min: 109.67ms avg: 28519.74ms max: 36760.02ms approx. 95 percentile: 31751.56ms Threads fairness: events (avg/stddev): 9.7656/0.81 execution time (avg/stddev): 278.5131/6.05 我们只需要关心测试的总时间(total time)即可。 CPU性能测试有一个需要注意的地方,上面的测试只使用了一个线程,如果在两个cpu processor不同的电脑上做比较,这是不公平的。公平的做法是指定合理的线程数,如下所示: sysbench --test=cpu --num-threads=`grep "processor" /proc/cpuinfo | wc -l` --cpu-max-prime=200000 run 补充知识: 查看CPU核数的方法 查看物理cpu个数 grep "physical id" /proc/cpuinfo | sort -u | wc -l 查看核心数量 grep "core id" /proc/cpuinfo | sort -u | wc -l 查看线程数量 grep "processor" /proc/cpuinfo | sort -u | wc -l 在sysbench的测试中,–num-threads取值为”线程数量”即可,再大的值没有什么意义,对测试结果也没有什么影响。 #3.2 线程(thread)测试 测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用。 sysbench --test=threads --num-threads=64 run 下面是输出结果: Number of threads: 64 Doing thread subsystem performance test Thread yields per test: 1000 Locks used: 8 Threads started! Done. Test execution summary: total time: 4.5845s total number of events: 10000 total time taken by event execution: 291.9995 per-request statistics: min: 0.76ms avg: 29.20ms max: 152.71ms approx. 95 percentile: 71.11ms Threads fairness: events (avg/stddev): 156.2500/5.81 execution time (avg/stddev): 4.5625/0.02 说实话,我也不怎么会分析这个测试结果,网上搜了半天也没有搜到,几乎所有的资料都是简单的罗列出测试结果, 也不告诉我们应该怎么分析,实在是太不照顾新手了。 我自己是通过(total time:)判断线程调度的性能的,下面是我在服务器上运行这个测试的输出: Number of threads: 64 Doing thread subsystem performance test Thread yields per test: 1000 Locks used: 8 Threads started! Done. Test execution summary: total time: 2.4829s total number of events: 10000 total time taken by event execution: 157.3468 per-request statistics: min: 0.21ms avg: 15.73ms max: 166.69ms approx. 95 percentile: 119.14ms Threads fairness: events (avg/stddev): 156.2500/22.25 execution time (avg/stddev): 2.4585/0.02 可以看到total time 比在我自己电脑上少了一半,服务器的线程调度肯定比普通电脑快多了。 #3.3 互斥锁(mutex) 测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。 sysbench --test=mutex --num-threads=16 --mutex-num=2048 \ --mutex-locks=1000000 --mutex-loops=5000 run 输出结果如下: Number of threads: 16 Doing mutex performance test Threads started! Done. Test execution summary: total time: 3.6123s total number of events: 16 total time taken by event execution: 57.6636 per-request statistics: min: 3580.79ms avg: 3603.98ms max: 3610.94ms approx. 95 percentile: 10000000.00ms Threads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 3.6040/0.01 为了不误导别人,我就不解释各参数的含义了,可以请参考这里。 ##3.4 内存测试 内存测试测试了内存的连续读写性能。 sysbench --test=memory --memory-block-size=8K --memory-total-size=2G --num-threads=16 run 上面这条语句指定了整个测试过程中,传输2G的数据量,每个block的大小为8K(大写的K)。 测试结果如下所示,我们最关心的是吞吐量(8030.45MB/sec),和后面的磁盘io 测试结果比较可知,内存的连续读写比磁盘的连续读写快十几倍。 Number of threads: 16 Doing memory operations speed test Memory block size: 8K Memory transfer size: 2048M Memory operations type: write Memory scope type: global Threads started! Done. Operations performed: 262144 (1027897.89 ops/sec) 2048.00 MB transferred (8030.45 MB/sec) Test execution summary: total time: 0.2550s total number of events: 262144 total time taken by event execution: 3.1911 per-request statistics: min: 0.00ms avg: 0.01ms max: 29.55ms approx. 95 percentile: 0.00ms Threads fairness: events (avg/stddev): 16384.0000/926.14 execution time (avg/stddev): 0.1994/0.02 ##3.5 文件IO基准测试 文件IO(fileio)基准测试可以测试系统在不同IO负载下的性能。这对于比较不同的硬盘驱动器,不同的RAID 卡,不同的RAID 模式,都很有帮助。可以根据测试结果调整IO子系统。文件IO基准测试模拟了很多InnoDB 的IO特性。 测试的第一步是准备(Prepare)阶段,生成测试用到的数据文件,生成的数据文件至少要比内存大。 如果文件中的数据能完全放入内存中,则操作系统 缓存大部分的数据,导致测试结果无法体现IO密集型的工作负载。首先通过下面的命令创建一个数据集: sysbench --test=fileio --file-total-size=40G prepare 这个命令会在当前工作目录下创建测试文件,后续的运行(run)阶段将通过读写这些文件进行测试。 第二步就是运行(run)阶段,针对不同的IO 类型有不同的测试选项: seqwr 顺序写入 seqrewr 顺序重写 seqrd 顺序读取 rndrd 随机读取 rndwr 随机写入 rndrw 混合随机读/写 下面的命令运行文件I/O混合随机读/写基准测试: sysbench --test=fileio --file-total-size=40G --file-test-mode=rndrw\ --init-rng=on --max-time=300 --max-requests=0 run 结果如下: Extra file open flags: 0 128 files, 240Mb each 30Gb total file size Block size 16Kb Number of random requests for random IO: 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 Threads started! Time limit exceeded, exiting... Done. Operations performed: 15900 Read, 10600 Write, 33842 Other = 60342 Total Read 248.44Mb Written 165.62Mb Total transferred 414.06Mb (1.3802Mb/sec) 88.33 Requests/sec executed Test execution summary: total time: 300.0074s total number of events: 26500 total time taken by event execution: 164.1563 per-request statistics: min: 0.01ms avg: 6.19ms max: 315.51ms approx. 95 percentile: 15.83ms Threads fairness: events (avg/stddev): 26500.0000/0.00 execution time (avg/stddev): 164.1563/0.00 输出结果中包含了大量的信息。和IO子系统密切相关的包括每秒请求数和总吞吐量。在上述例子中, 每秒请求数是88.33 Requests/sec , 吞吐量是1.3802Mb/sec 。另外,时间信息也非常有用, 尤其是大约95%的时间分布。这些数据对于评估磁盘性能十分有用。 测试完成以后,运行清除(cleanup)操作删除第一步生成的测试文件。 sysbench --test=fileio --fil-total-size=30G cleanup ##3.6 oltp 下面来看最重要也是最复杂的测试————oltp。oltp 基准测试模拟了一个简单的事物处理系统的工作负载。 下面的例子使用的是一张超过百万行记录的表,第一步是先生成这张表: sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test \ --mysql-user=root prepare 生成数据只需要上面这条简单的命令即可。这条命令在test 数据库中新建了一个表(sbtest),并在表中插入了1000000条记录。 对于非默认安装的mysql,需要指定连接到msyql服务器的socket(my.cnf中的socket值),如下所示: sysbench --test=oltp --oltp-table-size=1000000 --mysql-user=root \ --mysql-db=test --mysql-socket=/data/ntse/lmx/sysbench/var/mysqld.sock \ prepare 数据加载完成以后就可以开始测试了,这个例子采用了16个线程,测试时长为720秒: sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test \ --mysql-user=root --max-time=720 --max-requests=0 \ --num-threads=16 --oltp-test-mode=complex run 与插入记录时一样,如果mysql是非默认安装,还需要指定–mysql-socket的值。 Number of threads: 16 Doing OLTP test. Running mixed OLTP test Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases) Using "BEGIN" for starting transactions Using auto_inc on the id column Threads started! Time limit exceeded, exiting... (last message repeated 15 times) Done. OLTP test statistics: queries performed: read: 26225724 write: 9366330 other: 3746532 total: 39338586 transactions: 1873266 (2601.71 per sec.) deadlocks: 0 (0.00 per sec.) read/write requests: 35592054 (49432.47 per sec.) other operations: 3746532 (5203.42 per sec.) Test execution summary: total time: 720.0136s total number of events: 1873266 total time taken by event execution: 11506.8251 per-request statistics: min: 2.37ms avg: 6.14ms max: 400.48ms approx. 95 percentile: 14.90ms Threads fairness: events (avg/stddev): 117079.1250/275.62 execution time (avg/stddev): 719.1766/0.01 如上所示,结果中包含了相当多的信息。其中最有价值的信息如下; 总的事务数 每秒事务数 时间统计信息(最小,平均,最大响应时间,以及95%百分比响应时间) 线程公平性统计信息 最最重要的当然是每秒事务数(2601.71 per sec.)。 oltp 测试注意事项: **0.4版本的测试选项,0.5版本就通过lua的模式来测试。** –max-requests –max-requests 默认值为10000 ,如果设置了–max-requests 或者使用默认值 ,分析结果的时候主要查看运行时间(total time),一般情况下,都将–max-requests 赋值为0 ,即不限制请求数量,通过–max-time 来指定测试时长,然后查看系统的每秒事务数。 –oltp-test-mode –oltp-test-mode用以指定测试模式,取值有(simeple,complex,nontrx),默认是complex。不同模式会执行不同的语句。 具体执行语句如下所示: Simple 这种模式只是简单的执行selec语句。 SELECT c FROM sbtest WHERE id=N complex(Advanced transactional) 在事务中,可能包含下列语句。 Point queries: SELECT c FROM sbtest WHERE id=N Range queries: SELECT c FROM sbtest WHERE id BETWEEN N AND M Range SUM() queries: SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M Range ORDER BY queries: SELECT c FROM sbtest WHERE id between N and M ORDER BY c Range DISTINCT queries: SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c UPDATEs on index column: UPDATE sbtest SET k=k+1 WHERE id=N UPDATEs on non-index column: UPDATE sbtest SET c=N WHERE id=M DELETE queries: DELETE FROM sbtest WHERE id=N INSERT queries: INSERT INTO sbtest VALUES (...) nontrx(Non-transactional) 这种模式包含下列SQL语句。 Point queries: SELECT pad FROM sbtest WHERE id=N UPDATEs on index column: UPDATE sbtest SET k=k+1 WHERE id=N UPDATEs on non-index column: UPDATE sbtest SET c=N WHERE id=M DELETE queries: DELETE FROM sbtest WHERE id=N INSERT queries: INSERT INTO sbtest (k, c, pad) VALUES(N, M, S) simple 与 –oltp-read-only 的区别 simple模式和在complex模式下开启read-only选项都只包含select语句。但是 simple 模式只包含最简单的select语句,相反地,complex 模式中,如果我们开启read-only 选项,即--oltp-read-only=on,则会包含复杂的SQL语句。如: SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c 测试自有的存储引擎 测试自有的存储引擎需要告诉sysbench,这个存储引擎是否支持事务。 如下所示: 准备 sysbench --test=oltp --mysql-table-engine=tnt --mysql-engine-trx=yes \ --oltp-table-size=100000 --mysql-user=root --mysql-db=test \ --mysql-socket=/data/ntse/lmx/sysbench/var/mysqld.sock \ prepare 测试 sysbench --test=oltp --mysql-table-engine=tnt --mysql-engine-trx=yes \ --oltp-table-size=100000 --mysql-user=root --mysql-db=test \ --mysql-socket=/data/ntse/lmx/sysbench/var/mysqld.sock \ --oltp-test-mode=complex --num-threads=16 --max-time=720 \ --max-requests=0 run 清除 sysbench --test=oltp --mysql-table-engine=tnt --mysql-engine-trx=yes \ --oltp-table-size=100000 --mysql-user=root --mysql-db=test \ --mysql-socket=/data/ntse/lmx/sysbench/var/mysqld.sock \ clean