使用sysbench压测主机和数据库

交付服务器或数据库的时候,我们需要对服务器和数据库的性能有一定的了解。可以使用sysbench对系统做一些压测。

sysbench

sysbench下载

https://github.com/akopytov/sysbench

可以使用0.5版本,支持lua插件压测数据库

sysbench 数据库压测lua脚本例子

https://github.com/percona/sysbench-scripts

Usage:
  sysbench --test=<test-name> [options]... <command>

Commands: prepare run cleanup help version

General options:
  --num-threads=N             number of threads to use [1]
  --max-requests=N            limit for total number of requests [10000]
  --max-time=N                limit for total execution time in seconds [0]
  --forced-shutdown=STRING    amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE    size of stack per thread [64K]
  --tx-rate=N                 target transaction rate (tps) [0]
  --report-interval=N         periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
  --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
  --test=STRING               test to run
  --debug=[on|off]            print more debugging info [off]
  --validate=[on|off]         perform validation checks where possible [off]
  --help=[on|off]             print help and exit
  --version=[on|off]          print version and exit [off]
  --rand-init=[on|off]        initialize random number generator [off]
  --rand-type=STRING          random numbers distribution {uniform,gaussian,special,pareto} [special]
  --rand-spec-iter=N          number of iterations used for numbers generation [12]
  --rand-spec-pct=N           percentage of values to be treated as 'special' (for special distribution) [1]
  --rand-spec-res=N           percentage of 'special' values to use (for special distribution) [75]
  --rand-seed=N               seed for random number generator, ignored when 0 [0]
  --rand-pareto-h=N           parameter h for pareto distibution [0.2]
  --config-file=FILENAME      File containing command line options

Log options:
  --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [3]

  --percentile=N      percentile rank of query response times to count [95]

General database options:

  --db-driver=STRING  specifies database driver to use ('help' to get list of available drivers)
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
  --db-debug=[on|off] print database-specific debug information [off]

Compiled-in database drivers:
  mysql - MySQL driver

mysql options:
  --mysql-host=[LIST,...]      MySQL server host [localhost]
  --mysql-port=N               MySQL server port [3306]
  --mysql-socket=[LIST,...]    MySQL socket
  --mysql-user=STRING          MySQL user [sbtest]
  --mysql-password=STRING      MySQL password []
  --mysql-db=STRING            MySQL database name [sbtest]
  --mysql-table-engine=STRING  storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
  --mysql-engine-trx=STRING    whether storage engine used is transactional or not {yes,no,auto} [auto]
  --mysql-ssl=[on|off]         use SSL connections, if available in the client library [off]
  --mysql-compression=[on|off] use compression, if available in the client library [off]
  --myisam-max-rows=N          max-rows parameter for MyISAM tables [1000000]
  --mysql-debug=[on|off]       dump all client library calls [off]
  --mysql-ignore-errors=[LIST,...]list of errors to ignore, or "all" [1213,1020,1205]
  --mysql-dry-run=[on|off]     Dry run, pretent that all MySQL client API calls are successful without executing them [off]

Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test

See 'sysbench --test=<name> help' for a list of options for each test.

cpu

sysbench --test=cpu run

指定多个线程:
sysbench --test=cpu --num-threads=30 run

指定测试时间:
sysbench --test=cpu --max-time=10 run

指定测试请求数
sysbench --test=cpu --max-requests=100000 --num-threads=100 run

io

$ sysbench --test=fileio help
sysbench 0.5:  multi-threaded system evaluation benchmark

fileio options:
  --file-num=N                  number of files to create [128]
  --file-block-size=N           block size to use in all IO operations [16384]
  --file-total-size=SIZE        total size of files to create [2G]
  --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
  --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
  --file-async-backlog=N        number of asynchronous operatons to queue per thread [128]
  --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
  --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]
  --file-fsync-all=[on|off]     do fsync() after each write operation [off]
  --file-fsync-end=[on|off]     do fsync() at the end of test [on]
  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]
  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]
  --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

io测试中比较重要的几个参数:

file-test-mode: 读还是写?顺序访问还是随机访问? 对于数据库,需要测试重点关注随机IO的性能。

file-fsync-freq: 测试fsync的性能。

file-rw-ratio:读写比例

io 测试

准备测试文件

mkdir test
cd test
sysbench --test=fileio --file-test-mode=rndrw prepare

dtstack@test01:~/test$  ls -lh
total 2.0G
-rw------- 1 dtstack dtstack 16M Jun 28 23:00 test_file.0
-rw------- 1 dtstack dtstack 16M Jun 28 23:00 test_file.1
-rw------- 1 dtstack dtstack 16M Jun 28 23:00 test_file.10
-rw------- 1 dtstack dtstack 16M Jun 28 23:00 test_file.100
-rw------- 1 dtstack dtstack 16M Jun 28 23:00 test_file.101

运行压测, 随机读写
sysbench --test=fileio --file-test-mode=rndrw --max-requests=100000 --num-threads=16 run
压测运行过程中,注意观察io性能。比如我们的这个测试机器,写入iops 500左右,写数据吞度量8M/s, 响应时间近30ms,性能比较一般。

iostat -kx 3

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.33   115.00    5.33  488.00   114.67  7934.67    32.63    13.67   27.76   14.00   27.91   2.03 100.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.62    0.17    3.12   54.37    0.00   32.73

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00   121.00    5.00  474.00   128.00  7732.00    32.82    14.15   29.00    6.40   29.24   2.09 100.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           8.98    0.17    2.12   62.49    0.00   26.25

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               2.33   118.00    3.67  488.67   106.67  7909.33    32.56    14.56   30.03   17.09   30.12   2.03 100.00

测试内存分配和访问

dtstack@test01:~/test$ sysbench --test=memory help
sysbench 0.5:  multi-threaded system evaluation benchmark

memory options:
  --memory-block-size=SIZE    size of memory block for test [1K]
  --memory-total-size=SIZE    total size of data to transfer [100G]
  --memory-scope=STRING       memory access scope {global,local} [global]
  --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
  --memory-oper=STRING        type of memory operations {read, write, none} [write]
  --memory-access-mode=STRING memory access mode {seq,rnd} [seq]

dtstack@test01:~/test$ sysbench --test=memory --num-threads=64 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 64
Random number generator seed is 0 and will be ignored

Initializing worker threads...

Threads started!

Operations performed: 104857600 (890624.94 ops/sec)

102400.00 MB transferred (869.75 MB/sec)

MySQL压测

sysbench 0.5 使用lua插件的形式压测数据库。

--test 参数指定lua脚本,lua脚本的内容参考下面的例子,

或者参考

https://github.com/percona/sysbench-scripts

dtstack@test01:~/junda/sysbench-scripts/timeseries$ sysbench --test=insertv1.lua --mysql-host=127.0.0.1 --mysql-user=root --mysql-password=xx --max-requests=1000 prepare
sysbench 0.5:  multi-threaded system evaluation benchmark

Creating table 'sensordata' ...
dtstack@test01:~/junda/sysbench-scripts/timeseries$ sysbench --test=insertv1.lua --mysql-host=127.0.0.1 --mysql-user=root --mysql-password=xx --max-requests=1000 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored

Initializing worker threads...

最简单的lua脚本,往一个表插入数据

$ cat test.lua

function event(thread_id)
    db_query("insert into t1(a ) values(100)")
end
$ cat create.lua

function event(thread_id)
    for i = 1,10 do
      db_query("create table t" .. i .. "(a int)")
    end
end

$ cat drop.lua

function event(thread_id)
    for i = 1,10 do
      db_query("drop table if exists t" .. i  )
    end
end
时间: 2024-09-19 09:56:01

使用sysbench压测主机和数据库的相关文章

sysbench压测之MySQL压测的例子

基于OLTP的混合测试 大概是70%的读(select) 30%的写(insert, update, delete) 还是一样的分别对1 4 8 16 32 64线程做测试 [root@DS-VM-Node160 ~]# for i in 1 4 8 16 32 64; do sysbench --test=oltp --test=/usr/local/sysbench/tests/db/oltp.lua --db-driver=mysql --oltp-table-size=10000000

sysbench压测小记(r11笔记第99天)

对于很多线上业务而言,如果有新服务器,新的环境,新的业务,到底资源和预期的承载压力是否匹配,这个得用数据说话,或是通过严谨的论证来阐述. 比如一台新的服务器,一般都需要经过压力测试,我们也叫拷机测试.一般都会从多个维度来进行加压(比如CPU,内存,IO等等),看看服务器是否依旧坚挺,虽然这一点上如果产生了懈怠或者懒惰还是会被轻视,但是从身边的例子来看,还是会测试出一些问题来,如果发现了问题,就避免了后续的很多被动. sysbench就是这么一个工具,功能非常全面.是一个标准模块化,多线程的基准测

ECS上自建Redis服务压测报告

背景说明 最近处理的企业大客户问题中,出现好几例都是客户通过购买ECS进行自建Redis服务,并且在使用过程中碰到一些因云环境的内部限制等原因导致客户使用中碰到服务异常或者产品性能上无法满足业务需求的情况.每次处理过程都费时费力,TAM同学一直不辞辛苦的跟进,也拉动了ECS/Redis 研发,网络,存储等同学进去排查,又是抓包又是电话会议,最终可能排查下来都是因为场景使用上的不合理,导致客户在该过程用的不爽,我们支持得也累. 这里根据目前客户通常采用的Redis主备Sentinel架构模式,在E

innodb compression原理以及性能压测

压缩算法:innodb plugin采用了 zlib library函式库的LZ77 的压缩算法来对数据进行压缩,这种算法已经很成熟,在cpu利用率,压缩比率在50%以上,更为重要的是无数据丢失: innodb的数据存储方式:innodb在数据储存上采用聚簇的方式(B-树)来组织数据,叶子节点上存放了表中定义的所有列数据:第二索引同样也是B-树结构,在索引列的后面会加上聚簇键列,用于索引列到聚簇索引查找数据: 压缩B-树:由于对B-树的频繁的更新,进而导致B-树的页节点的分裂,不断的对数据进行解

三体PCC大赛题目 - facebook\微博 like场景 数据库设计与性能压测

标签 PostgreSQL , pipelinedb , facebook , 微博 , 流式统计 背景 高可用架构的一个PCC大赛,看了一下比赛规则,发现PostgreSQL很适合做这个场景,原样复刻,使用PG实现以及性能表现到底如何? 比赛内容介绍如下 https://github.com/archnotes/PCC 实现类似 facebook 中的 like 功能,需要: 可以对一个对象(一条feed.文章.或者url)进行 like 操作,禁止 like 两次,第二次 like 返回错误

压测之sysbench安装和MySQL只读测试

sysbench编译安装 [root@DS-VM-Node160 ~]# cd /tmp/ [root@DS-VM-Node160 /tmp]# git clone https://github.com/akopytov/sysbench.git [root@DS-VM-Node160 /tmp]# cd sysbench/ [root@DS-VM-Node160 /tmp/sysbench]# yum install mysql mysql-devel libtool openssl-deve

Apache Jmeter3.0压测数据库OOM的Bug排查

一.引言 Apache Jmeter 2.13(以下简称Jmeter2)版本后,2.X系列就作古了.前些日子,Apache Jmeter 3.0(以下简称Jmeter3)版本正式发布,新生的事物,功能肯定强大了很多,但作为开源产品,稳定性自然要打些折扣,一位同学前几天在使用Jmeter3时不幸中招. 二.问题描述 原本好用的JDBC请求脚本,压测数据库,使用Jmeter3版本时直接OOM,回退至Jmeter2,一切正常,啥也别说,肯定是又出Bug了,本着求实的精神,咱来看看Jmeter3为毛OO

从尿检取中段谈数据库压测

想必大家都参加过一年一次的体检,在进行尿液体检的时候,医生会告诉你要留中段尿!要留中段尿!要留中段尿!重要的事情说三遍. 为什么尿液化验要取中段尿呢?因为前段尿和后段尿容易被污染,所以在进行尿常规和尿培养检查时都建议留取中段尿. 我们在做数据库压测时,也会遇到类似的情况,比如一个持续数天的TPCC压测,tps在时间曲线上的表现可能会是这样的:开始时tps缓慢的攀升,然后会经过一个较长时间的平稳期,(期间可能还有有一些短暂的抖动),最后又会以非常平缓的曲线开始性能慢慢下降. 简单分析前段TPS攀升

压测2.0:云压测 + APM = 端到端压测解决方案

从压力测试说起 压力测试是确立系统稳定性的一种测试方法,通常在系统正常运作范围之外进行,以考察其功能极限和隐患.与功能测试不同,压测是以软件响应速度为测试目标的,尤其是针对在较短时间内大量并发用户的访问时,软件的抗压能力. 至于为什么产品或业务系统在通过功能测试后还需要进行压力测试,原因很简单,因为它重要,为什么重要?众所周知,响应速度是用户体验的核心指标之一. SmartBear 数据表明,如果 Amazon 的加载时间延长1秒,那么一年就会减少16亿美元的营收.用户与网站互动的过程中,如果加