Sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试,数据库目前支持MySQL/Oracle/PostgreSQL。
一、安装:
Github地址:
https://github.com/akopytov/sysbench
RHEL/CentOS:
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bashsudo yum -y install sysbenchSysbench可以测试如下:
•   oltp_*.lua: a collection of OLTP-like database benchmarks(脚本默认放在/usr/share/sysbench/)
•   fileio: a filesystem-level benchmark
•   cpu: a simple CPU benchmark
•   memory: a memory access benchmark
•   threads: a thread-based scheduler benchmark
•   mutex: a POSIX mutex benchmark二、相关信息:
1、通用选项:
General options:            # 通用选项--threads=N               要使用的线程数,默认 1 个 [1]--events=N                最大允许的事件个数,默认为[0]--time=N                  最大的总执行时间,以秒为单位默认为[10]--thread-stack-size=SIZE     每个线程的堆栈大小,默认为[64K]--rate=N                   指定数量多少事件(事务)平均每秒钟应该执行的所有线程。0(默认)意味着无限的速率,即事件尽快执行--report-interval=N          以秒为单位定期报告具有指定间隔的中间统计信息, 0 禁用中间报告,默认为0--debug[=on|off]             打印更多 debug 信息 [off]--validate[=on|off]            尽可能执行验证检查 [off]--help[=on|off]               显示帮助信息并退出 [off]--version[=on|off]             显示版本信息并退出 [off]--config-file=FILENAME        包含命令行选项的文件--tables=N                   表数量(数据库测试)--table-size=N                   表大小--tx-rate=N                   废弃,改用 --rate [0]--max-requests=N             废弃,改用 --events [0]--max-time=N                 废弃,改用 --time [0]--num-threads=N              废弃,改用 --threads [1]2、数据库专用选项:
mysql options:              # MySQL 数据库专用选项--mysql-host=[LIST,...]          MySQL server host [localhost]--mysql-port=[LIST,...]          MySQL server port [3306]--mysql-socket=[LIST,...]        MySQL socket--mysql-user=STRING              --mysql-password=STRING         --mysql-db=STRING               --mysql-ssl[=on|off]             --mysql-ssl-cipher=STRING       --mysql-compression[=on|off]     --mysql-debug[=on|off]          --mysql-ignore-errors=[LIST,...] --mysql-dry-run[=on|off]         pgsql options:              # PostgreSQL 数据库专用选项--pgsql-host=STRING     --pgsql-port=N          --pgsql-user=STRING     --pgsql-password=STRING --pgsql-db=STRING       3、脚本:
默认放在/usr/share/sysbench/,有如下脚本
bulk_insert.lua;
oltp_delete.lua;
oltp_point_select.lua;
oltp_read_write.lua;
oltp_update_non_index.lua;
select_random_points.lua;
oltp_common.lua;
oltp_insert.lua;
oltp_read_only.lua;
oltp_update_index.lua;
oltp_write_only.lua;
select_random_ranges.lua
三、测试:
这里仅做数据库测试,其他测试可以是用sysbench –help,sysbench cpu help等查看相应参数。
流程:1、建测试表及数据;2、进行测试;3清除数据。(1、prepare;2、run;3、cleanup)
1、 建测试表及数据:
线程,数据表大小及数量及其他参数按需求修改即可
sysbench oltp_read_write.lua --time=60 --mysql-host=192.168.100.127 --mysql-port=3506 --mysql-user=test --mysql-password=123456 --mysql-db=pcms --table-size=10000 --tables=2 --threads=2 prepare
2、 测试数据:
sysbench oltp_read_write.lua --time=60 --mysql-host=192.168.100.127 --mysql-port=3506 --mysql-user=test --mysql-password=123456 --mysql-db=pcms --table-size=10000 --tables=2 --threads=2 run
3、 清洗数据:
sysbench oltp_read_write.lua --time=60 --mysql-host=192.168.100.127 --mysql-port=3506 --mysql-user=test --mysql-password=123456 --mysql-db=pcms --table-size=10000 --tables=2 --threads=2 cleanup
(直接删除测试表当然也可以~)
转载于:https://blog.51cto.com/bilibili/2173243