zoukankan      html  css  js  c++  java
  • 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 create 1
    --max-requests Limit for total number of requests. 0 means unlimited 10000
    --max-time Limit for total execution time in seconds. 0 (default) means unlimited 0
    --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 thread 32K
    --init-rnd Specifies if random numbers generator should be initialized from timer before the test start off
    --test Name of the test mode to run Required
    --debug Print more debug info off
    --validate Perform validation of test results where possible off
    --help Print help on general syntax or on a test mode specified with --test, and exit off
    --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 possible off
    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性能测试

    准备对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 支持的表存储引擎类型。

    下面是相关的配置

    Option Description Default value
    --oltp-test-mode Execution mode (see above). Possible values: simpe (simple), complex (advanced transactional) and nontrx (non-transactional) complex
    --oltp-read-only Read-only mode. No UPDATE, DELETE or INSERT queries will be performed. off
    --oltp-skip-trx Omit BEGIN/COMMIT statements, i.e. run the same queries as the test would normally run but without using transactions. off
    --oltp-reconnect-mode Reconnect mode. Possible values:
    session Don't reconnect (i.e. each thread disconnects only at the end of the test)
    query Reconnect after each SQL query
    transaction Reconnect after each transaction (if transactions are used in the selected DB test)
    random One of the above modes is randomly chosen for each transaction
    session
    --oltp-range-size Range size for range queries 100
    --oltp-point-selects Number of point select queries in a single transaction 10
    --oltp-simple-ranges Number of simple range queries in a single transaction 1
    --oltp-sum-ranges Number of SUM range queries in a single transaction 1
    --oltp-order-ranges Number of ORDER range queries in a single transaction 1
    --oltp-distinct-ranges Number of DISTINCT range queries in a single transaction 1
    --oltp-index-updates Number of index UPDATE queries in a single transaction 1
    --oltp-non-index-updates Number of non-index UPDATE queries in a single transaction 1
    --oltp-nontrx-mode Type of queries for non-transactional execution mode (see above). Possible values: select, update_key, update_nokey, insert, delete. select
    --oltp-connect-delay Time in microseconds to sleep after each connection to database 10000
    --oltp-user-delay-min Minimum time in microseconds to sleep after each request 0
    --oltp-user-delay-max Maximum time in microseconds to sleep after each request 0
    --oltp-table-name Name of the test table sbtest
    --oltp-table-size Number 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-pct Percentage of values to be treated as 'special' (for special distribution) 1
    --oltp-dist-res Percentage of cases when 'special' values are generated (for special distribution) 75
    --db-ps-mode If 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:

    Option Description Default 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-port MySQL server port (in case TCP/IP connection should be used) 3306
    --mysql-socket Unix socket file to communicate with the MySQL server  
    --mysql-user MySQL user user
    --mysql-password MySQL password  
    --mysql-db MySQL 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-engine Type of the test table. Possible values: myisam, innodb, heap, ndbcluster, bdb, maria, falcon, pbxt innodb
    --mysql-ssl Use SSL connections. no
    --myisam-max-rows MAX_ROWS option for MyISAM tables (required for big tables) 1000000
    --mysql-create-options Additional 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)

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

  • 相关阅读:
    [Github]在仓库中添加Sponsor赞助者按钮
    SpringMVC面试题常问的29道(附答案)
    Spring常问面试题及答案汇总(2020版)
    Java面试题及答案整理(2020最新版)
    MySQL数据库下载及安装教程(最新版!史上最详细!)
    +0与-0在plc传递数值上的坑
    halcon极坐标转换与亮暗缺陷检测结合的案例(转)
    互联网项目管理
    zabbix 监控IO DISK
    转 更改当前schema
  • 原文地址:https://www.cnblogs.com/morebetter/p/1536118.html
Copyright © 2011-2022 走看看