linux Command sysbench 线程压力测试工具(1)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: linux Command sysbench 线程压力测试工具(1)

linux Command sysbench 线程压力测试工具

文章目录

linux Command sysbench 线程压力测试工具

1. 简介

2. 安装

2.1 Ubuntu

2.2 centos

2.3 编译安装

3. 参数

3.1 sysbench --test=fileio help

3.2 sysbench --test=cpu help

3.3 sysbench --test=memory help

3.4 sysbench --test=threads help

3.5 sysbench --test=mutex help

3.6 sysbench --test=oltp help

4. 测试

4.1 测试 CPU

4.2 测试线程

4.3 测试 IO

4.4 测试内存

4.5 测试 mutex

4.6 测试 OLTP

4.7 测试OLTP 结合lua脚本

1. 简介

sysbench 是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。当前功能允许测试的系统参数有:


file I/O performance (文件I / O性能)

scheduler performance (调度性能)

memory allocation and transfer speed (内存分配和传输速度)

POSIX threads implementation performance (POSIX线程执行绩效)

database server performance (OLTP benchmark) (数据库服务器性能)

2. 安装

2.1 Ubuntu

apt-get install sysbench

2.2 centos

yum -y install epel-release
yum -y update
yum install sysbench

2.3 编译安装

下载: sysbench-1.0.20

apt-get -y install automake libtool libtool-bin
sysbench-1.0.20.zip
unzip 
cd sysbench-1.0.20
mkdir /usr/sysbench/
./autogen.sh

要是出现:perl: warning: Falling back to the standard locale

(“C”)。则需要设置locale:

echo "export LC_ALL=C" >> /root/.bashrc
source /root/.bashrc

要是没有安装开发包,即/usr/include/ 目录下面没有mysql文件夹。则需要执行安装(版本为12.04):

sudo apt-get -y install libmysqlclient-dev
sudo apt-get -y install libmysqld-dev
sudo apt-get -y install libmysqld-pic

执行configure操作:

./configure --prefix=/usr/sysbench/ --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/li

说明:


–prefix=/usr/sysbench/ :指定sysbench的安装目录。

–with-mysql-includes=/usr/include/mysql/ :指定安装mysql时候的includes目录。

–with-mysql-libs=/usr/lib/mysql/ :指定装mysql时候的lib目录。

–with-mysql :sysbench默认支持mysql,如果需要测试oracle或者pgsql则需要制定–with-oracle或者–with-pgsql。

cp /usr/bin/libtool /root/sysbench-1.0.20
make && make install 

3. 参数

$ sysbench --help
Usage:
  sysbench [options]... [testname] [command]
Commands implemented by most tests: prepare run cleanup help
General options:
  --threads=N                     number of threads to use [1]
  --events=N                      limit for total number of events [0]
  --time=N                        limit for total execution time in seconds [10]
  --forced-shutdown=STRING        number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off] #超过max-time强制中断。默认是off。
  --thread-stack-size=SIZE        size of stack per thread [64K]  #每个线程的堆栈大小。默认是32K。
  --rate=N                        average transactions rate. 0 for unlimited rate [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. []
  --debug[=on|off]                print more debugging info [off]
  --validate[=on|off]             perform validation checks where possible [off]
  --help[=on|off]                 print help and exit [off]
  --version[=on|off]              print version and exit [off]
  --config-file=FILENAME          File containing command line options
  --tx-rate=N                     deprecated alias for --rate [0]
  --max-requests=N                deprecated alias for --events [0]  #请求的最大数目。默认为10000,0代表不限制。
  --max-time=N                    deprecated alias for --time [0]  #最大执行时间,单位是s。默认是0,不限制
  --num-threads=N                 deprecated alias for --threads [1]  #创建测试线程的数目。默认为1.
Pseudo-Random Numbers Generator options:
  --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. When 0, the current time is used as a RNG seed. [0]
  --rand-pareto-h=N  parameter h for pareto distribution [0.2]
Log options:
  --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
  --percentile=N       percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]
  --histogram[=on|off] print latency histogram in report [off]
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
  pgsql - PostgreSQL driver
mysql options:
  --mysql-host=[LIST,...]          MySQL server host [localhost]
  --mysql-port=[LIST,...]          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-ssl[=on|off]             use SSL connections, if available in the client library [off]
  --mysql-ssl-cipher=STRING        use specific cipher for SSL connections []
  --mysql-compression[=on|off]     use compression, if available in the client library [off]
  --mysql-debug[=on|off]           trace 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, pretend that all MySQL client API calls are successful without executing them [off]
pgsql options:
  --pgsql-host=STRING     PostgreSQL server host [localhost]
  --pgsql-port=N          PostgreSQL server port [5432]
  --pgsql-user=STRING     PostgreSQL user [sbtest]
  --pgsql-password=STRING PostgreSQL password []
  --pgsql-db=STRING       PostgreSQL database name [sbtest]
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

3.1 sysbench --test=fileio help

$ sysbench  --test=fileio help
sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
fileio options:
  --file-num=N   创建测试文件的数量。默认是128
  --file-block-size=N  测试时文件块的大小。默认是16384(16K)
  --file-total-size=SIZE   测试文件的总大小。默认是2G
  --file-test-mode=STRING  文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
  --file-io-mode=STRING   文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
  --file-extra-flags=STRING   使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
  --file-fsync-freq=N   执行fsync()的频率。(0 – 不使用fsync())。默认是100
  --file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off
  --file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on
  --file-fsync-mode=STRING  使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
  --file-merged-requests=N   如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0
  --file-rw-ratio=N     测试时的读写比例。默认是1.5

3.2 sysbench --test=cpu help

$ sysbench  --test=cpu help
sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
cpu options:
  --cpu-max-prime=N upper limit for primes generator [10000] 最大质数发生器数量。默认是10000

3.3 sysbench --test=memory help

$ sysbench  --test=memory help
sysbench 0.4.12:  multi-threaded system evaluation benchmark
memory options:
  --memory-block-size=SIZE  测试时内存块大小。默认是1K
  --memory-total-size=SIZE    传输数据的总大小。默认是100G
  --memory-scope=STRING    内存访问范围{global,local}。默认是global
  --memory-hugetlb=[on|off]  从HugeTLB池内存分配。默认是off
  --memory-oper=STRING     内存操作类型。{read, write, none} 默认是write
  --memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq

3.4 sysbench --test=threads help

threads options:
  --thread-yields=N   每个请求产生多少个线程。默认是1000
  --thread-locks=N    每个线程的锁的数量。默认是8

3.5 sysbench --test=mutex help

mutex options:
  --mutex-num=N    数组互斥的总大小。默认是4096
  --mutex-locks=N    每个线程互斥锁的数量。默认是50000
  --mutex-loops=N    内部互斥锁的空循环数量。默认是10000

3.6 sysbench --test=oltp help

oltp options:
  --oltp-test-mode=STRING    执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex
  --oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
  --oltp-sp-name=STRING   存储过程的名称。默认为空
  --oltp-read-only=[on|off]  只读模式。Update,delete,insert语句不可执行。默认是off
  --oltp-skip-trx=[on|off]   省略begin/commit语句。默认是off
  --oltp-range-size=N      查询范围。默认是100
  --oltp-point-selects=N          number of point selects [10]
  --oltp-simple-ranges=N          number of simple ranges [1]
  --oltp-sum-ranges=N             number of sum ranges [1]
  --oltp-order-ranges=N           number of ordered ranges [1]
  --oltp-distinct-ranges=N        number of distinct ranges [1]
  --oltp-index-updates=N          number of index update [1]
  --oltp-non-index-updates=N      number of non-index updates [1]
  --oltp-nontrx-mode=STRING   查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} [select]
  --oltp-auto-inc=[on|off]      AUTO_INCREMENT是否开启。默认是on
  --oltp-connect-delay=N     在多少微秒后连接数据库。默认是10000
  --oltp-user-delay-min=N    每个请求最短等待时间。单位是ms。默认是0
  --oltp-user-delay-max=N    每个请求最长等待时间。单位是ms。默认是0
  --oltp-table-name=STRING  测试时使用到的表名。默认是sbtest
  --oltp-table-size=N         测试表的记录数。默认是10000
  --oltp-dist-type=STRING    分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special
  --oltp-dist-iter=N    产生数的迭代次数。默认是12
  --oltp-dist-pct=N    值的百分比被视为'special' (for special distribution)。默认是1
  --oltp-dist-res=N    ‘special’的百分比值。默认是75
General database options:
  --db-driver=STRING  数据库类型,指定数据库驱动程序('help' to get list of available drivers)
  --db-ps-mode=STRING 数据库预处理模式{auto, disable} [auto]
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=STRING         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]
  --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]
  --mysql-create-options=STRING additional options passed to CREATE TABLE []


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2天前
|
JSON 测试技术 网络安全
Apifox工具让我的 Socket.IO 测试效率翻倍
用了 Apifox 测试 Socket.IO 后,我整个人都升级了!不仅操作简单到令人发指,功能还贼全面,真的是 提升开发效率的神器 !
|
1月前
|
监控 安全 Ubuntu
Linux下如何安装配置Fail2ban防护工具
通过以上步骤,可以在Linux系统中成功安装和配置Fail2ban,从而有效保护服务器免受暴力破解等攻击。Fail2ban通过实时监控日志文件,自动更新防火墙规则,为系统安全提供了一层重要的保护。
135 36
|
2月前
|
Rust Ubuntu Java
[Linux工具] Makefile
Makefile是Linux环境下用于自动化编译和链接程序的配置文件,常用于简化大型项目的编译流程。通过定义目标文件、依赖文件及生成命令,Makefile能高效管理编译任务。它不仅适用于C语言项目,还可扩展到其他编程语言和非编程任务中。
63 20
[Linux工具] Makefile
|
24天前
|
Linux API
Linux下载工具wget与curl
`wget` 是一个用于从网络下载文件的命令行工具,支持HTTP、HTTPS和FTP协议。它能自动处理下载中断,并支持递归下载网站内容。基本用法:`wget URL`,可指定文件名(`-O`)、保存目录(`-P`),还支持断点续传(`-c`)、限速(`--limit-rate`)和递归下载(`-r`)。相比之下,`curl` 更侧重于发送各种HTTP请求(如GET、POST),并支持文件上传、自定义请求头和cookie等功能。
57 10
|
21天前
|
存储 Ubuntu 前端开发
Linux软件包管理工具概览
在Linux系统中,dpkg、apt、rpm、yum和dnf是几种常见的包管理工具,它们分别属于不同的Linux发行版或家族,并有着各自的诞生顺序和特点。下面将按照这些工具的诞生顺序,并结合Debian、Red Hat、CentOS、Ubuntu和Kali等系统,进行详细的介绍。
25 4
|
2月前
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
152 28
|
2月前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
61 11
|
10月前
|
Web App开发 测试技术 API
自动化测试工具Selenium的深度解析
【5月更文挑战第27天】本文旨在深入剖析自动化测试工具Selenium,探讨其架构、原理及应用。通过对其核心组件、运行机制及在实际项目中的应用案例进行详细解读,以期为软件测试人员提供全面、深入的理解与实践指导。
|
10月前
|
JSON 数据管理 测试技术
自动化测试工具Selenium Grid的深度应用分析深入理解操作系统的内存管理
【5月更文挑战第28天】随着互联网技术的飞速发展,软件测试工作日益复杂化,传统的手工测试已无法满足快速迭代的需求。自动化测试工具Selenium Grid因其分布式执行特性而受到广泛关注。本文旨在深入剖析Selenium Grid的工作原理、配置方法及其在复杂测试场景中的应用优势,为测试工程师提供高效测试解决方案的参考。
|
10月前
|
敏捷开发 监控 IDE
深入理解自动化测试工具Selenium的工作原理与实践应用
【5月更文挑战第26天】 随着敏捷开发和持续集成理念的普及,自动化测试在软件开发生命周期中扮演了至关重要的角色。Selenium作为最流行的自动化测试工具之一,以其开源、跨平台和支持多种编程语言的特性被广泛使用。本文将详细解析Selenium的核心组件,探讨其工作原理,并通过案例分析展示如何高效地实施Selenium进行Web应用的自动化测试。我们将从测试准备到结果分析的全过程,提供一系列实用的策略和最佳实践,帮助读者构建和维护一个健壮的自动化测试环境。

热门文章

最新文章