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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
简介: 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
相关文章
|
3月前
|
安全 Linux 虚拟化
|
30天前
|
弹性计算 运维 Ubuntu
os-copilot在Alibaba Cloud Linux镜像下的安装与功能测试
我顺利使用了OS Copilot的 -t -f 功能,我的疑惑是在换行的时候就直接进行提问了,每次只能写一个问题,没法连续换行更有逻辑的输入问题。 我认为 -t 管道 功能有用 ,能解决环境问题的连续性操作。 我认为 -f 管道 功能有用 ,可以单独创建可连续性提问的task问题。 我认为 | 对文件直接理解在新的服务器理解有很大的帮助。 此外,我还有建议 可以在非 co 的环境下也能进行连续性的提问。
70 7
|
1月前
|
安全 Linux 测试技术
Intel Linux 内核测试套件-LKVS介绍 | 龙蜥大讲堂104期
《Intel Linux内核测试套件-LKVS介绍》(龙蜥大讲堂104期)主要介绍了LKVS的定义、使用方法、测试范围、典型案例及其优势。LKVS是轻量级、低耦合且高代码覆盖率的测试工具,涵盖20多个硬件和内核属性,已开源并集成到多个社区CICD系统中。课程详细讲解了如何使用LKVS进行CPU、电源管理和安全特性(如TDX、CET)的测试,并展示了其在实际应用中的价值。
|
2月前
|
Linux Shell 网络安全
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
本指南介绍如何利用 HTA 文件和 Metasploit 框架进行渗透测试。通过创建反向 shell、生成 HTA 文件、设置 HTTP 服务器和发送文件,最终实现对目标系统的控制。适用于教育目的,需合法授权。
88 9
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
|
2月前
|
安全 Ubuntu Linux
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
60 9
Metasploit Pro 4.22.6-2024111901 (Linux, Windows) - 专业渗透测试框架
|
3月前
|
缓存 Ubuntu Linux
Linux环境下测试服务器的DDR5内存性能
通过使用 `memtester`和 `sysbench`等工具,可以有效地测试Linux环境下服务器的DDR5内存性能。这些工具不仅可以评估内存的读写速度,还可以检测内存中的潜在问题,帮助确保系统的稳定性和性能。通过合理配置和使用这些工具,系统管理员可以深入了解服务器内存的性能状况,为系统优化提供数据支持。
105 4
|
3月前
|
关系型数据库 MySQL 测试技术
【赵渝强老师】MySQL的基准测试与sysbench
本文介绍了MySQL数据库的基准测试及其重要性,并详细讲解了如何使用sysbench工具进行测试。内容涵盖sysbench的安装、基本使用方法,以及具体测试MySQL数据库的步骤,包括创建测试数据库、准备测试数据、执行测试和清理测试数据。通过这些步骤,可以帮助读者掌握如何有效地评估MySQL数据库的性能。
152 5
|
3月前
|
安全 程序员 API
|
3月前
|
存储 安全 UED
多线程在打包工具中的运用
【11月更文挑战第2天】本文介绍了多线程技术在打包工具中的应用,包括提高打包效率、优化用户体验和多线程安全考虑。通过并行处理文件和加速资源收集,多线程可以显著缩短打包时间。在用户体验方面,多线程使界面保持响应,并支持优先级处理。此外,文章还讨论了资源访问冲突和死锁预防的解决方案,确保多线程环境下的稳定性和安全性。
|
4月前
|
前端开发 JavaScript 应用服务中间件
linux安装nginx和前端部署vue项目(实际测试react项目也可以)
本文是一篇详细的教程,介绍了如何在Linux系统上安装和配置nginx,以及如何将打包好的前端项目(如Vue或React)上传和部署到服务器上,包括了常见的错误处理方法。
1276 0
linux安装nginx和前端部署vue项目(实际测试react项目也可以)