如何对Linux系统进行基准测试4工具Sysbench

news/2024/9/20 2:36:24/文章来源:https://www.cnblogs.com/testing-/p/18299756

Sysbench简介

Sysbench是一款多用途基准测试工具,可对CPU、内存、I/O甚至数据库性能进行测试。它是一个基本的命令行工具,提供了直接、简便的系统测试方法。github地址:https://github.com/akopytov/sysbench 。

主要功能:

  • CPU: 衡量CPU执行计算密集型任务的能力。
  • 内存: 衡量内存子系统的性能。
  • 磁盘I/O: 衡量磁盘读写速度。
  • 数据库: 衡量数据库的性能,包括 OLTP(联机事务处理)和TPC-C基准测试。
  • 其他: Sysbench还支持其他类型的测试,例如线程性能和网络延迟。

Sysbench的主要特点包括:

  • 开源: Sysbench 是一个开源软件,可以免费使用和修改。
  • 跨平台: Sysbench 支持多种操作系统,包括 Linux、Windows、macOS 和 Solaris。
  • 多线程: Sysbench 支持多线程测试,可以充分利用多核 CPU 的性能。
  • 模块化: Sysbench 的架构是模块化的,可以扩展支持新的测试类型和功能。
  • 易用性: Sysbench 提供命令行界面和 Lua 脚本支持,易于使用和配置。

Sysbench 常用于以下场景:

  • 性能测试: 评估系统的性能瓶颈并进行优化。
  • 数据库性能测试: 衡量数据库的性能并与其他数据库进行比较。
  • 硬件评估: 评估新硬件的性能。
  • 容量规划: 规划系统的容量以满足未来的需求。

源码:https://github.com/akopytov/sysbench

安装Sysbench

首先在系统上安装Sysbench。大多数发行版软件源都提供了它:

# Ubuntu/Debian
$ sudo apt install sysbench# Fedora
# dnf install sysbench# CentOS
# yum install sysbench# OpenSUSE
# zypper in sysbench

CPU基准测试

$ sysbench cpu --cpu-max-prime=2000 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)Running the test with following options:
Number of threads: 1
Initializing random number generator from current timePrime numbers limit: 2000Initializing worker threads...Threads started!CPU speed:events per second: 22757.61General statistics:total time:                          10.0001stotal number of events:              227609Latency (ms):min:                                    0.04avg:                                    0.04max:                                    0.1295th percentile:                        0.04sum:                                 9968.18Threads fairness:events (avg/stddev):           227609.0000/0.00execution time (avg/stddev):   9.9682/0.00

虽然会生成包含大量统计数据的报告,但 CPU 基准测试的主要内容是"General statistics"下的"total time"。

  • 其他命令:
$ sysbench cpu run
$ sysbench cpu --threads=40 run # 默认为单线程
#在检查 CPU 在重负载下的性能时,可使用命令将 CPU 的最大质数限制从 "10000 "扩展到 "15000":
$ sysbench --test=cpu --cpu-max-prime=15000 run 
# 帮助
$ sysbench cpu help
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)cpu options:--cpu-max-prime=N upper limit for primes generator [10000]

内存基准测试

$ sysbench memory --threads=2 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)Running the test with following options:
Number of threads: 2
Initializing random number generator from current timeRunning memory speed test with the following options:block size: 1KiBtotal size: 102400MiBoperation: writescope: globalInitializing worker threads...Threads started!Total operations: 28555430 (2855143.49 per second)27886.16 MiB transferred (2788.23 MiB/sec)General statistics:total time:                          10.0001stotal number of events:              28555430Latency (ms):min:                                    0.00avg:                                    0.00max:                                    0.0395th percentile:                        0.00sum:                                12842.67Threads fairness:events (avg/stddev):           14277715.0000/1030637.00execution time (avg/stddev):   6.4213/0.10

这里有两点需要考虑:"Total operations"和"transferred"。

  • 其他命令:
$ sysbench memory run
$ sysbench memory --memory-oper=write run # 默认为读
# 要测试特定条件下的内存,例如将内存块大小从默认的 "1KiB "提高到 "1M",同时保持总内存容量为 "8GB"
$ sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run

参考资料

  • 软件测试精品书籍文档下载持续更新 https://github.com/china-testing/python-testing-examples 请点赞,谢谢!
  • 本文涉及的python测试开发库 谢谢点赞! https://github.com/china-testing/python_cn_resouce
  • python精品书籍下载 https://github.com/china-testing/python_cn_resouce/blob/main/python_good_books.md
  • Linux精品书籍下载 https://www.cnblogs.com/testing-/p/17438558.html
  • https://linuxtechlab.com/benchmark-linux-systems-install-sysbench-tool/
  • https://webhostinggeeks.com/howto/how-to-setup-sysbench-for-cpu-and-memory-benchmarking-on-a-linux-machine/
  • https://vegastack.com/tutorials/how-to-use-sysbench-for-linux-performance-testing/

IO基准测试

在Linux系统上执行IO基准测试时,我们必须先创建一些测试文件。要创建测试文件,请使用以下命令:

$ sysbench --test=fileio --file-total-size=100G prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)128 files, 819200Kb each, 102400Mb total
Creating files for the test...
Extra file open flags: (none)
Extending existing file test_file.0
...
Extending existing file test_file.127
53687091200 bytes written in 94.39 seconds (542.44 MiB/sec).

请确保选择的测试文件大小大于内存容量,这样IO进程才不会受到内存操作的影响。创建测试文件将根据所选大小花费一些时间。创建测试文件后,运行以下命令开始基准测试:

$ sysbench --test=fileio --file-total-size=100G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)Running the test with following options:
Number of threads: 1
Initializing random number generator from current timeExtra file open flags: (none)
128 files, 800MiB each
100GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...Threads started!File operations:reads/s:                      1101.01writes/s:                     734.01fsyncs/s:                     2348.98Throughput:read, MiB/s:                  17.20written, MiB/s:               11.47General statistics:total time:                          300.0508stotal number of events:              1255287Latency (ms):min:                                    0.00avg:                                    0.24max:                                 2154.6095th percentile:                        0.46sum:                               299665.82Threads fairness:events (avg/stddev):           1255287.0000/0.00execution time (avg/stddev):   299.6658/0.00

文件清理:

$ sysbench --test=fileio --file-total-size=100G cleanup
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)Removing test files...

Mysql基准测试

要对mysql进行基准测试,我们首先要在名为"test"的数据库中创建一个有50000 的表,使用以下命令

$ sysbench --test=oltp –oltp-table-size=50000 --mysql-db=test --mysql-user=root --mysql-password=passwd prepare

操作完成后,执行以下命令启动 Mysql Bechmarking:

$ sysbench --test=oltp --oltp-table-size=500000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
No DB drivers specified, using mysqlRunning the test with following options:Number of threads: 8Doing OLTP test.Running mixed OLTP testDoing read-only testUsing Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)Using "BEGIN" for starting transactionsUsing auto_inc on the id columnThreads started!Time limit exceeded, exiting...(last message repeated 7 times)Done.OLTP test statistics:queries performed:read: 2253860write: 0other: 321980total: 2575840transactions: 160990 (2683.06 per sec.)deadlocks: 0 (0.00 per sec.)read/write requests: 2253860 (37562.81 per sec.)other operations: 321980 (5366.12 per sec.)Test execution summary:total time: 60.0024stotal number of events: 160990total time taken by event execution: 479.3419per-request statistics:min: 0.81msavg: 2.98msmax: 3283.40msapprox. 95 percentile: 4.62msThreads fairness:events (avg/stddev): 20123.7500/63.52execution time (avg/stddev): 59.9177/0.00Main parameter to check here is 'transactions per second'transactions: 160990 (2683.06 per sec.)

测试数据清理:

$ sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup

结果解读

总时间越短,表明系统性能越好,尤其是在比较类似测试时。不过必须将这一指标与其他指标结合起来考虑,因为测试时间越短,错误率越高,并不代表性能越好。

Ops/sec是系统吞吐量的直接指标。ops/sec值越高,通常意味着系统在给定时间内可以处理的操作越多,性能越好。例如,如果您运行的是数据库服务器,较高的ops/sec表示您的服务器每秒可以处理更多的查询,从而为最终用户带来更快的响应时间。

延迟对用户体验至关重要。较低的延迟意味着更快地完成操作,这对于视频流或在线游戏等需要实时响应的任务尤为重要。如果您正在托管一个网站,较低的延迟可以加快页面加载时间,提升用户体验。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/743200.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

containerd 容器基础环境组件的搭建

1 基础环境说明(1)本次所有部署软件版本说明软件名称 版本号操作系统内核(后续升级为 lt-5.4.278)CentOS 7.9.2009 (3.10.0-1160.el7) 1c1GB 20GBCentOS-7-x86_64-Minimal-2009.isocontainerd v1.6.6cfssl v1.6.1cni v1.1.1crictl v1.24.2nerdctl 1.7.6buildkit v0.14.1(2)系统…

【JavaScript】聊一聊js中的浅拷贝与深拷贝与手写实现

什么是深拷贝与浅拷贝?深拷贝与浅拷贝是js中处理对象或数据复制操作的两种方式。‌在聊深浅拷贝之前咱得了解一下js中的两种数据类型:前言 什么是深拷贝与浅拷贝?深拷贝与浅拷贝是js中处理对象或数据复制操作的两种方式。‌在聊深浅拷贝之前咱得了解一下js中的两种数据类型:…

分页查询及其拓展应用案例

分页查询 分页查询是处理大量数据时常用的技术,通过分页可以将数据分成多个小部分,方便用户逐页查看。SQLAlchemy 提供了简单易用的方法来实现分页查询。 本篇我们也会在最终实现这样的分页效果:1. 什么是分页查询 分页查询是将查询结果按照一定数量分成多页展示,每页显示固…

delphi dev cxgrid 列绑定Richedti 支持过滤

默认是不支持过滤的,这里需要改到内部的一些源码文件。 先说思路: 1.要让列支持过滤需要重载richedit类的 GetSupportedOperations,typeTcxRichEditProperties = class(cxRichEdit.TcxRichEditProperties)publicfunction GetSupportedOperations: TcxEditSupportedOperation…

《项目管理》-笔记1

PMBOK解读 1.1项目和项目管理 项目:项目是为创造独特的产品、服务或成果而进行的临时性工作。 项目管理:在项目的活动中运用知识、技术、工具、技巧,以满足项目要求。 1.2十大知识领域 (1)项目整合管理 项目整合管理包括为识别、定义、组合、统一和协调各项目管理过程组的各…

Cilium Ingress 特性(转载)

Cilium Ingress 特性Cilium Ingress 特性(转载) 一、环境信息主机 IPubuntu 10.0.0.234软件 版本docker 26.1.4helm v3.15.0-rc.2kind 0.18.0kubernetes 1.23.4ubuntu os Ubuntu 22.04.6 LTSkernel 5.15.0-106二、Cilium Ingress 流程图Cilium 现在提供了开箱即用的 Kuberne…

N1盒子挂载阿里云盘-Alist工具

Markdown Example.centered-text { text-align: center; font-size: 40px; font-family: "Times New Roman", Georgia, serif }N1盒子挂载阿里云盘安装Alist手动安装 参考:官方文档step 1step 2配置-启动step 3打开web网页:http://192.168.1.254:5244/ 登录界面、拉…

WindowsLinux搭建frp内网穿透(自用)

Linux服务器搭建服务端 1、下载官方frp包,软件是开源的,下载链接: https://github.com/fatedier/frp/releases 根据自己的版本需求,自行下载对应的版本号,本文章以0.37版本为例wget -c https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_amd64…

2024-07-13:用go语言,给定一个从0开始的长度为n的整数数组nums和一个从0开始的长度为m的整数数组pattern,其中pattern数组仅包含整数-1、0和1。 一个子数组nums[i.

2024-07-13:用go语言,给定一个从0开始的长度为n的整数数组nums和一个从0开始的长度为m的整数数组pattern,其中pattern数组仅包含整数-1、0和1。 一个子数组nums[i..j]的大小为m+1,如果满足以下条件,则我们称该子数组与模式数组pattern匹配: 1.若pattern[k]为1,则nums[i+…

dbeaver

修改字体 参考 【DBeaver】常用自定义设置 旧版 编辑器字体查询结果字体新版 应用字体编辑器字体修改背景色 编辑器背景色注意: 此设置会同时修改查询结果背景色,但是需要重启 dbeaver格式化配置 参考 【DBeaver】常用自定义设置 格式化大小写关闭自动插入表别名关于语句分隔符…

动态规划的“三步走”方法

“三步走”方法 动态规划问题种类较多,但大多都能通过“三步走”方法解决。状态表示:将具体问题抽象为数学问题,明确需要表示的状态,数组中的下标分别表示哪种状态。 状态转移:状态转移相当于递推公式。主要有两种方式,可以从上一个状态转移到当前状态,或者从当前状态转…

N1盒子挂载磁盘-解决盒子重启后无法自动挂载问题

Markdown Example.centered-text { text-align: center; font-size: 40px; font-family: "Times New Roman", Georgia, serif }N1盒子挂载磁盘挂载步骤: step 1step 2如果提示挂载已存在、就先卸载挂载分区step 3 回到首页重新挂载step 4此时已经挂载成功、但是默认…