zdc253212956 发表于 2018-10-3 13:06:45

Sysbench 性能压测及MySQL性能压测

  sysbench支持以下几种测试模式:
  1、CPU运算性能
  2、磁盘IO性能
  3、调度程序性能
  4、内存分配及传输速度
  5、POSIX线程性能
  6、数据库性能(OLTP基准测试)
  1.安装
  采用yum epel安装为1.0版本(测试0.X版本与1.X版本差异比较大参数都不同)
  2.CPU测试
  对CPU的性能测试通常有:1.质数计算;2圆周率计算;sysbench使用的就是通过质数相加的测试。对CPU测试直接运行run即可。
  sysbench --threads=20 --events=10000 --debug=on --test=cpu --cpu-max-prime=20000 run
  20个线程执行1万条请求,每个请求执行质数相加到20000
  3.内存测试
  测试8K顺序分配:
  sysbench --threads=12 --events=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
  测试8K随机分配。
  sysbench --threads=12 --events=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
  4.文件io测试
  IO的测试主要用于测试IO的负载性能。主要测试选项为--file-test-mode。还有可以关注的参数包括--file-block-size、--file-io-mode、--file-fsync-freq 、--file-rw-ratio,具体参数含义请见参数解释章节。
  sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw prepare
  sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw run
  sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw cleanup
  对比两台服务器的io性能,需要跑相同的线程
  5.锁测试
  互斥锁测试模拟所有线程在同一时刻并发运行。
  sysbench --threads=12 mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 run
  6.线程测试
  sysbench threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
  7.OLTP测试
  oltp是针对数据库的基准测试,例如每次对数据库进行优化后执行基准测试来测试不同的配置的tps。sysbench 0.5之后通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua
  预置条件:
  a)创建数据库:
  mysqladmin create sbtest -uroot –p
  或者
  SQL>create database sbtest
  b)增加权限:

  grant usage on . to 'sbtest'@'%'>  其中密码通过如下命令获取:
  select password('sbtest');
  +-------------------------------------------+
  | password('sbtest') |
  +-------------------------------------------+
  | 2AFD99E79E4AA23DE141540F4179F64FFB3AC521 |
  +-------------------------------------------+
  1 row in set (0.00 sec)
  c)增加权限:
  GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX ON sbtest. TO 'sbtest'@"%";
  grant all privileges on . to 'sbtest'@'%';
  flush privileges;
  或者简单粗暴:

  create user 'sbtest'@'127.0.0.1'>  grant all privileges on . to
  flush privileges;
  e)OLTP测试:
  准备阶段:
  sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on prepare
  测试阶段:
  命令如下:
  sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on run
  清理阶段:
  sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on cleanup
  最后删除数据库
  SQL>drop database sbtest;
  参数解释
  通过命令sysbench –help可以了解各参数的具体解释
  --test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
  --oltp_tables_count=10 表示会生成 10 个测试表
  --oltp-table-size=100000 表示每个测试表填充数据量为 100000
  --mysql-engine-trx=STRING指定不同的存储引擎测试。
  --oltp-test-mode=STRING测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
  --oltp-sp-name=STRING指定存储过程进行语句测试
  --oltp-table-size=N指定表的记录大小,默认
  --oltp-num-tables=N指定测试表的数量,默认1
  --rand-init=on 表示每个测试表都是用随机数据来填充的
  --file-num=N创建测试文件的数量,默认128个

  --file-block-size=N block>  --file-total-size=SIZE所有文件的总大小,默认2G
  --file-test-mode=STRING测试类型 {seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)} --file-io-mode=STRING I/O模式,需要系统支持默认sync
  --file-async-backlog=N每个线程的异步操作队列数,默认128个,需要--file-io-mode=async;
  --file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
  --file-fsync-freq=N当请求数达到多少时执行fsync()刷新,默认100,0代表过程中不执行fsync()
  --file-fsync-all= 执行每一个写操作后执行fsync()刷新操作,默认关闭off --file-fsync-end= 测试结束执行fsync()操作,默认开启on --file-fsync-mode=STRING 同步刷新方法,默认fsync {fsync, fdatasync} --file-merged-requests=N合并指定数量的IO请求,0代表不合并,默认0 --file-rw-ratio=N 读写比例,默认1.5/1
  mysql基本语法
  #启动数据库
  systemctl start mariadb
  #链接
  mysql -h 主机地址 -u 用户名 -p 用户密码
  #显示数据库
  show databases;
  #判断是否存在数据库wpj1105,有的话先删除
  drop database if exists testdb;
  #创建数据库
  create database testdb;
  #删除数据库
  drop database testdb;
  #使用该数据库
  use testdb;
  #显示数据库中的表
  show tables;
  查看MySQL用户权限:
  show grants for 你的用户
  如:
  show grants for root@'localhost';
  show grants for 'test'@'%';
  回收权限
  revoke ALL PRIVILEGES ON . from 'test'@'%';

页: [1]
查看完整版本: Sysbench 性能压测及MySQL性能压测