首页 > 数据库 > MySQL > 正文

MYSQL压力测试工具sysbench安装测试过程详解

2024-07-24 12:35:30
字体:
来源:转载
供稿:网友
  sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试,数据库目前支持MySQL/Oracle/PostgreSQL,下面我们来看看它的安装与测试.
 
  如果评测一台mysql数据库的压力,可以使用sysbench来测试,具体的操作出下,先安装sysbench工具,安装操作如下.
 
  安装环境
 
  CentOS release 5.4 (Final),MySQL 5.1.40 MySQL_HOME=/usr/local/mysql/,Sysbench 0.4.12
 
  安装步骤
 
  1.去http://sourceforge.net/projects/sysbench/下载最新版本的sysbench 0.4.12
 
  2.解压缩sysbench-0.4.12.tar.gz
 
  tar --zxvf sysbench-0.4.12.tar.gz
 
  3.进入解压缩包 sysbench-0.4.12,并执行脚本autogen.sh
 
  cd sysbench-0.4.12
 
  ./autogen.sh
 
  4.关键的三部曲:configure&make&make install
 
  第一步准备:创建表结构:
 
  bin/sysbench --test=oltp /           --测试类型数据库oltp
  --mysql-host=127.0.0.1 /             --mysql主机
  --mysql-port=3421 /                  --mysql端口
  --mysql-user=root /                  --mysql登陆用户
  --mysql-password=$password /         --mysql密码
  --mysql-db=test /                    --mysql测试数据库名
  --mysql-socket=/var/mysql.sock /     --socket位置
  --oltp-table-name=sbtest /             --mysql测试表名
  --mysql-table-engine=innodb /        --mysql表使用存储引擎
  --oltp-table-size=1 prepare    --表数据量
  将表名修改为uncompressed
 
  rename table sbtest to uncompressed;
 
  再次创建表sbtest,并将表名修改为compressed
 
  rename table sbtest to compressed;
 
  将表改为compressed
 
  alter table compressed ROW_FORMAT=compressed;
 
  第二步:向表uncompressed表中添加记录
 
  bin/sysbench --test=oltp           /
  --mysql-host=127.0.0.1 /             --mysql主机
  --mysql-port=3421 /                  --mysql端口
  --mysql-user=root /                  --mysql登陆用户
  --mysql-password=$password /         --mysql密码
  --mysql-db=test /                    --mysql测试数据库名
  --mysql-socket=/var/mysql.sock /     --socket位置
  --oltp-table-name=uncompressed /             --mysql测试表名
  --mysql-table-engine=innodb /        --mysql表使用存储引擎
  --oltp-nontrx-mode=insert      /
  --oltp-test-mode=nontrx        /
  --max-requests=1000000            /
  --max-time=600                 /
  --num-threads=100 run
  --测试结果:
  OLTP test statistics:
      queries performed:
          read:                            0
          write:                           1001110
          other:                           0
          total:                           1001110
      transactions:                        1001110 (13617.75 per sec.)
      deadlocks:                           0      (0.00 per sec.)
      read/write requests:                 1001110 (13617.75 per sec.)
      other operations:                    0      (0.00 per sec.)
  Test execution summary:
      total time:                          73.5151s
      total number of events:              1001110
      total time taken by event execution: 7346.0036
      per-request statistics:
           min:                                  0.10ms
           avg:                                  7.34ms
           max:                                239.05ms
           approx.  95 percentile:              22.00ms
  Threads fairness:
      events (avg/stddev):           10011.1000/86.80
      execution time (avg/stddev):   73.4600/0.00
  说明:总共消耗了73s,每秒达到13617个事务.
 
  第三步:向表compressed表中添加记录:
 
  bin/sysbench --test=oltp           /
  --mysql-host=127.0.0.1 /             --mysql主机
  --mysql-port=3421 /                  --mysql端口
  --mysql-user=root /                  --mysql登陆用户
  --mysql-password=$password /         --mysql密码
  --mysql-db=test /                    --mysql测试数据库名
  --mysql-socket=/var/mysql.sock /     --socket位置
  --oltp-table-name=compressed /             --mysql测试表名
  --mysql-table-engine=innodb /        --mysql表使用存储引擎
  --oltp-nontrx-mode=insert      /
  --oltp-test-mode=nontrx        /
  --max-requests=1000000            /
  --max-time=600                 /
  --num-threads=100 run
  --测试结果:
  OLTP test statistics:
      queries performed:
          read:                            0
          write:                           1000515
          other:                           0
          total:                           1000515
      transactions:                        1000515 (2313.85 per sec.)
      deadlocks:                           0      (0.00 per sec.)
      read/write requests:                 1000515 (2313.85 per sec.)
      other operations:                    0      (0.00 per sec.)
  Test execution summary:
      total time:                          432.4036s
      total number of events:              1000515
      total time taken by event execution: 43229.6698
      per-request statistics:
           min:                                  0.10ms
           avg:                                 43.21ms
           max:                                730.32ms
           approx.  95 percentile:             133.46ms
  Threads fairness:
      events (avg/stddev):           10005.1500/109.30
      execution time (avg/stddev):   432.2967/0.01
  说明:总共消耗了432s,每秒处理2313事务数,和uncompressed的速度相差6倍.
 
  4.测试案例,表属性compress对复合操作速度的影响.
 
  第一步:准备数据,和第3项一样准备.
 
  第二步:针对compressed表进行复合操作测试.
 
  bin/sysbench --test=oltp           /
  --mysql-host=127.0.0.1 /             --mysql主机
  --mysql-port=3421 /                  --mysql端口
  --mysql-user=root /                  --mysql登陆用户
  --mysql-password=$password /         --mysql密码
  --mysql-db=test /                    --mysql测试数据库名
  --mysql-socket=/var/mysql.sock /     --socket位置
  --oltp-table-name=compressed /             --mysql测试表名
  --mysql-table-engine=innodb /        --mysql表使用存储引擎
  --max-requests=1000000            /
  --max-time=600                 /
  --num-threads=100 run
  OLTP test statistics:
      queries performed:
          read:                            14012236
          write:                           5004356
          other:                           2001743
          total:                           21018335
      transactions:                        1000869 (3145.37 per sec.)
      deadlocks:                           5      (0.02 per sec.)
      read/write requests:                 19016592 (59762.20 per sec.)
      other operations:                    2001743 (6290.75 per sec.)
  Test execution summary:
      total time:                          318.2043s
      total number of events:              1000869
      total time taken by event execution: 31800.5571
      per-request statistics:
           min:                                  3.19ms
           avg:                                 31.77ms
           max:                                344.54ms
           approx.  95 percentile:              53.37ms
  Threads fairness:
      events (avg/stddev):           10008.6900/32.50
      execution time (avg/stddev):   318.0056/0.01
  说明:共消耗时间318s,每秒3145个事务.
 
  第三步:针对uncompressed表进行复合操作测试.
 
  bin/sysbench --test=oltp           /
  --mysql-host=127.0.0.1 /             --mysql主机
  --mysql-port=3421 /                  --mysql端口
  --mysql-user=root /                  --mysql登陆用户
  --mysql-password=$password /         --mysql密码
  --mysql-db=test /                    --mysql测试数据库名
  --mysql-socket=/var/mysql.sock /     --socket位置
  --oltp-table-name=uncompressed /             --mysql测试表名
  --mysql-table-engine=innodb /        --mysql表使用存储引擎
  --oltp-nontrx-mode=insert      /
  --oltp-test-mode=nontrx        /
  --max-requests=1000000            /
  --max-time=600                 /
  --num-threads=100 run
  OLTP test statistics:
      queries performed:
          read:                            14013370
          write:                           5004769
          other:                           2001908
          total:                           21020047
      transactions:                        1000953 (3389.22 per sec.)
      deadlocks:                           2      (0.01 per sec.)
      read/write requests:                 19018139 (64395.20 per sec.)
      other operations:                    2001908 (6778.44 per sec.)
  Test execution summary:
      total time:                          295.3347s
      total number of events:              1000953
      total time taken by event execution: 29512.3204
      per-request statistics:
           min:                                  3.37ms
           avg:                                 29.48ms
           max:                                157.93ms
           approx.  95 percentile:              48.19ms
  Threads fairness:
      events (avg/stddev):           10009.5300/30.59
      execution time (avg/stddev):   295.1232/0.02
  说明:共消耗时间295s,每秒3389个事务,在复合操作中,compressed的表会快一些.

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表