第44章 sysbench数据库压测工具 - xiaoboluo768/qianjinliangfang GitHub Wiki

44.1.1 yum安装

# RHEL/CentOS
[root@localhost~]# curl -s https://packagecloud.io/install/repositories/akopytov/\ sysbench/script.rpm.sh | sudo bash
[root@localhost~]# sudo yum -y install sysbench

44.1.2 RPM包安装

[root@localhost~]# yum install mysql-libs postgresql-libs -y
[root@localhost~]# rpm -Uvh sysbench-1.0.7-13.el6.x86_64.rpm --nodeps
 
[root@localhost~]# ln -s /usr/lib64/mysql/libmysqlclient.so.18 /usr/lib64/ libmysqlclient_r.\ so.16

44.1.3 编译安装

# RHEL/CentOS
[root@localhost~]# yum -y install make automake libtool pkgconfig libaio-devel vim-\
common git
## For MySQL support, replace with mysql-devel on RHEL/CentOS 5
[root@localhost~]# yum -y install mariadb-devel
## For PostgreSQL support
[root@localhost~]# yum -y install postgresql-devel

[root@localhost~]# wget https://github.com/akopytov/sysbench/archive/1.0.13.tar.gz
[root@localhost~]# tar zxf sysbench-1.0.13.tar.gz

[root@localhost~]# cd sysbbench-1.0.13
[root@localhost~]# ./autogen.sh
## Add --with-pgsql to build with PostgreSQL support
[root@localhost~]# ./configure
[root@localhost~]# make
[root@localhost~]# make install

44.1.4 验证安装是否成功

[root@localhost~]# sysbench --version  

44.2.1 造数

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host =127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db= sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable\ prepare

44.2.2 数据库读写测试

  • 1.oltp_read_write
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host =127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench –mysql\ -db =sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable\ run
  • 2.oltp_read_only
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_read_only --db-ps-mode=disable\ run
  • 3.oltp_delete
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_delete --db-ps-mode=disable run
  • 4.oltp_update_index
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_update_index --db-ps-mode=disable\ run
  • 5.oltp_update_non_index
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_update_non_index --db-ps-mode=\ disable run
  • 6.oltp_insert
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_insert --db-ps-mode=disable run
  • 7.oltp_write_only
[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 \
–mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench –mysql\
-db=sbtest --tables=32 --table-size=5000000 oltp_write_only --db-ps-mode=disable run

44.2.3 清理

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable\ cleanup

44.3.2 options

# 指定oltp_read_write测试名称来查看额外的帮助选项
[root@localhost ]# sysbench oltp_read_write help  
......

44.3.3 testname

  • 1.sysbench Lua脚本介绍
[root@localhost~]# ls -lh /usr/share/sysbench/ /usr/share/sysbench/tests/include/\ oltp_legacy
......
  • 2.自定义Lua脚本
# calls prepare()
[root@localhost~]# sysbench --test=test.lua prepare
# calls event() in a loop
[root@localhost~]# sysbench --test=test.lua --num-threads=16 --report-interval=1 run 
......
$ sysbench --test=test.lua cleanup # calls cleanup()

44.4 数据库测试输出信息详解

[root@localhost~]# sysbench --db-driver=mysql --time=10 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qb
......

上一篇:第43章 HammerDB在线事务处理测试 | 下一篇:第45章 mysqladmin和innotop工具详解