# sysbench性能测试工具

## sysbench

[sysbench](https://github.com/akopytov/sysbench)是给予LuaJIT的多线程性能测试工具。通常用于测试数据库性能，但是也可以创建抽象的负载负载用于测试多种场景:

* `oltp_*.lua` 一系列OLTP类的数据库压测
* `fileio` 文件系统层对压测
* `cpu` 简单的CPU压测
* `memory` 内存访问压测
* `threads` 基于线程的调度器压测
* `mutex` 一个POSIX mutex压测

## 安装

[sysbench测试案例](https://wiki.mikejung.biz/Sysbench)提供了多种平台的安装方法，例如，可以通过EPEL

[sysbench GitHub文档](https://github.com/akopytov/sysbench)提供方法：

```bash
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
```

### 源代码安装

## 压测案例

* 测试8个cpu的虚拟机性能

```bash
sysbench cpu --threads=8 --time=300 --cpu-max-prime=100000 run
```

> `cpu-max-prime` 寻找最大素数
>
> `time` 持续时间，默认是`--time=0`表示不限制时间

输出举例

```
sysbench 1.0.9 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 8
Initializing random number generator from current time


Prime numbers limit: 100000

Initializing worker threads...

Threads started!

CPU speed:
    events per second:   278.78

General statistics:
    total time:                          300.0210s
    total number of events:              83639

Latency (ms):
         min:                                 27.98
         avg:                                 28.69
         max:                                126.48
         95th percentile:                     33.12
         sum:                            2399991.83

Threads fairness:
    events (avg/stddev):           10454.8750/37.61
    execution time (avg/stddev):   299.9990/0.01
```

## 参考

* [sysbench GitHub文档](https://github.com/akopytov/sysbench)
* [sysbench测试案例](https://wiki.mikejung.biz/Sysbench)
* [How To Benchmark Your System (CPU, File IO, MySQL) With sysbench](https://www.howtoforge.com/how-to-benchmark-your-system-cpu-file-io-mysql-with-sysbench)
* [Gentoo: Sysbench](https://wiki.gentoo.org/wiki/Sysbench)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/performance/utilities/sysbench.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
