sysbench介绍

1.概述 
sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于测试系统及数据库的性能。它主要包括以下几种方式的测试:
    1、cpu性能(系统级别)
    2、磁盘io性能(系统级别)
    3、调度程序性能(系统级别)
    4、内存分配及传输速度(系统级别)
    5、POSIX线程性能(系统级别)
    6、数据库性能(OLTP基准测试)
    目前sysbench主要支持 MySQL,pgsql,oracle 这3种数据库。
2. 命令格式:
sysbench [common-options] --test=name [test-options] command

Common-option list:
Option Description Default value
--num-threads The total number of worker threads to create1
--max-requests Limit for total number of requests. 0 means unlimited10000
--max-time Limit for total execution time in seconds. 0 (default) means unlimited0
--forced-shutdown

Amount of time to wait after --max-time before forcing shutdown. The value can be either an absolute number of seconds or as a percentage of the --max-time value by specifying a number of percents followed by the '%' sign.

"off" (the default value) means that no forced shutdown will be performed.

off
--thread-stack-size Size of stack for each thread32K
--init-rnd Specifies if random numbers generator should be initialized from timer before the test startoff
--test Name of the test mode to run Required
--debug Print more debug infooff
--validate Perform validation of test results where possible off
--help Print help on general syntax or on a test mode specified with --test, and exitoff
--verbosity Verbosity level (0 - only critical messages, 5 - debug)4
--percentile

SysBench measures execution times for all processed requests to display statistical information like minimal, average and maximum execution time. For most benchmarks it is also useful to know a request execution time value matching some percentile (e.g. 95% percentile means we should drop 5% of the most long requests and choose the maximal value from the remaining ones).

This option allows to specify a percentile rank of query execution times to count

95
--batch Dump current results periodically
off
--batch-delay Delay between batch dumps in secods
300
--validate Perform validation of test results where possibleoff
3. 测试CPU
sysbench --test=cpu --cpu-max-prime=20000 run
cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值。
4. 线程测试
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
5.

准备对IO测试

./sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run prepare

数据量一定要大于内存可存放的数据量。因为内存可以保存数据,那么操作系统会缓存这些数据,以及I/O边界测试就不能反映出正确的结果了。我们来创建一个数据集

开始测试

./sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run

清除测试数据

./sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run cleanup

上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读。


6. 内存测试

    sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
    上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。


7. OLTP测试(mysql数据库的基准测试)

 准备数据

./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root
prepare

开始测试

./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --
max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run

运行8个并发下,60s内只读的基准测试。


sysbench --num-threads=8 --max-requests=1000000 --test=oltp --mysql-table-engine=innodb --oltp-table-size=10000000 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=xxxx --mysql-db=sbtest run       

上述参数指定了本次测试的表存储引擎类型为 myisam,这里需要注意的是,官方网站上的参数有一处有误,即 --mysql-table-engine,官方网站上写的是 --mysql-table-type,这个应该是没有及时更新导致的。另外,指定了表最大记录数为 1000000,其他参数就很好理解了,主要是指定登录方式。测试 OLTP 时,可以自己先创建数据库 sbtest,或者自己用参数 --mysql-db 来指定其他数据库 。--mysql-table-engine 还可以指定为 innodb 等 MySQL 支持的表存储引擎类型。

下面是相关的配置

OptionDescriptionDefault value
--oltp-test-modeExecution mode (see above). Possible values: simpe (simple), complex (advanced transactional) and nontrx (non-transactional)complex
--oltp-read-onlyRead-only mode. No UPDATE, DELETE or INSERT queries will be performed. off
--oltp-skip-trxOmit BEGIN/COMMIT statements, i.e. run the same queries as the test would normally run but without using transactions. off
--oltp-reconnect-modeReconnect mode. Possible values:
sessionDon't reconnect (i.e. each thread disconnects only at the end of the test)
queryReconnect after each SQL query
transactionReconnect after each transaction (if transactions are used in the selected DB test)
randomOne of the above modes is randomly chosen for each transaction
session
--oltp-range-sizeRange size for range queries100
--oltp-point-selectsNumber of point select queries in a single transaction 10
--oltp-simple-rangesNumber of simple range queries in a single transaction 1
--oltp-sum-rangesNumber of SUM range queries in a single transaction 1
--oltp-order-rangesNumber of ORDER range queries in a single transaction 1
--oltp-distinct-rangesNumber of DISTINCT range queries in a single transaction 1
--oltp-index-updatesNumber of index UPDATE queries in a single transaction 1
--oltp-non-index-updatesNumber of non-index UPDATE queries in a single transaction 1
--oltp-nontrx-modeType of queries for non-transactional execution mode (see above). Possible values: select, update_key, update_nokey, insert, delete. select
--oltp-connect-delayTime in microseconds to sleep after each connection to database 10000
--oltp-user-delay-minMinimum time in microseconds to sleep after each request 0
--oltp-user-delay-maxMaximum time in microseconds to sleep after each request 0
--oltp-table-nameName of the test table sbtest
--oltp-table-sizeNumber of rows in the test table 10000
--oltp-dist-type

Distribution of random numbers. Possible values: uniform (uniform distribution), gauss (gaussian distribution) and special.

With special distribution a specified percent of numbers is generated in a specified percent of cases (see options below).

special
--oltp-dist-pctPercentage of values to be treated as 'special' (for special distribution) 1
--oltp-dist-resPercentage of cases when 'special' values are generated (for special distribution) 75
--db-ps-modeIf the database driver supports Prepared Statements API, SysBench will use server-side prepared statements for all queries where possible. Otherwise, client-side (or emulated) prepared statements will be used. This option allows to force using emulation even when PS API is available. Possible values: disable, auto. auto

Also, each database driver may provide its own options. Currently only MySQL driver is available. Below is a list of MySQL-specific options:

OptionDescriptionDefault value
--mysql-host

MySQL server host.

Starting from version 0.4.5 you may specify a list of hosts separated by commas. In this case SysBench will distribute connections between specified MySQL hosts on a round-robin basis. Note that all connection ports and passwords must be the same on all hosts. Also, databases and tables must be prepared explicitely on each host before executing the benchmark.

localhost
--mysql-portMySQL server port (in case TCP/IP connection should be used) 3306
--mysql-socketUnix socket file to communicate with the MySQL server 
--mysql-userMySQL user user
--mysql-passwordMySQL password  
--mysql-dbMySQL database name. Note SysBench will not automatically create this database. You should create it manually and grant the appropriate privileges to a user which will be used to access the test table. sbtest
--mysql-table-engineType of the test table. Possible values: myisam, innodb, heap, ndbcluster, bdb, maria, falcon, pbxt innodb
--mysql-sslUse SSL connections. no
--myisam-max-rowsMAX_ROWS option for MyISAM tables (required for big tables) 1000000
--mysql-create-optionsAdditional options passed to CREATE TABLE.  

默认情况下,OLTP会创建一个100行的数据库,数据库具体的定义为

	  CREATE TABLE `sbtest` (
`id` int(10) unsigned NOT NULL auto_increment,
`k` int(10) unsigned NOT NULL default '0',
`c` char(120) NOT NULL default '',
`pad` char(60) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `k` (`k`);
执行模分为:
1)Simple
SELECT c FROM sbtest WHERE id=N
其中N是1到--oltp-range-size的随机值
2)Advanced transactional
每个事物包含下列语句:
  • Point queries:
    SELECT c FROM sbtest WHERE id=N

  • Range queries:
    SELECT c FROM sbtest WHERE id BETWEEN N AND M 

  • Range SUM() queries:
    SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M

  • Range ORDER BY queries:
    SELECT c FROM sbtest WHERE id between N and M ORDER BY c

  • Range DISTINCT queries:
    SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c

  • UPDATEs on index column:
    UPDATE sbtest SET k=k+1 WHERE id=N 

  • UPDATEs on non-index column:
    UPDATE sbtest SET c=N WHERE id=M 

  • DELETE queries:
    DELETE FROM sbtest WHERE id=N 

  • INSERT queries:
    INSERT INTO sbtest VALUES (...) 
3) Non-transactional
这个类似于simple mode,但你可以选择任意的sql语句去测试,可选择的sql语句有:
  • Point queries:
    SELECT pad FROM sbtest WHERE id=N
  • UPDATEs on index column:
    UPDATE sbtest SET k=k+1 WHERE id=N
  • UPDATEs on non-index column:
    UPDATE sbtest SET c=N WHERE id=M
  • DELETE queries:
    DELETE FROM sbtest WHERE id=N
    The generated row IDs are unique over each test run, so no row is deleted twice.
  • INSERT queries:
    INSERT INTO sbtest (k, c, pad) VALUES(N, M, S)

8. 互斥锁测试(mutex)

在大部分时间,线程并发的情形下,仅仅获取互斥锁来测量互斥性能。(互斥十一哥数据结果,保证了独自的访问一些资源,避免了并发访问所引起的问题。)

转载于:https://www.cnblogs.com/morebetter/archive/2009/08/04/1536118.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值