wg/wrk

wrk - a HTTP benchmarking tool
wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.

An optional LuaJIT script can perform HTTP request generation, response processing, and custom reporting. Details are available in SCRIPTING and several examples are located in scripts/.

Basic Usage
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open.

Output:

Running 30s test @ http://127.0.0.1:8080/index.html
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 635.91us 0.89ms 12.92ms 93.69%
Req/Sec 56.20k 8.07k 62.00k 86.54%
22464657 requests in 30.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec: 606.33MB
Command Line Options
-c, --connections: total number of HTTP connections to keep open with
each thread handling N = connections/threads

-d, --duration: duration of the test, e.g. 2s, 2m, 2h

-t, --threads: total number of threads to use

-s, --script: LuaJIT script, see SCRIPTING

-H, --header: HTTP header to add to request, e.g. “User-Agent: wrk”

--latency:     print detailed latency statistics

--timeout:     record a timeout if a response is not received within
               this amount of time.

Benchmarking Tips
The machine running wrk must have a sufficient number of ephemeral ports available and closed sockets should be recycled quickly. To handle the initial connection burst the server’s listen(2) backlog should be greater than the number of concurrent connections being tested.

A user script that only changes the HTTP method, path, adds headers or a body, will have no performance impact. Per-request actions, particularly building a new HTTP request, and use of response() will necessarily reduce the amount of load that can be generated.

Acknowledgements
wrk contains code from a number of open source projects including the ‘ae’ event loop from redis, the nginx/joyent/node.js ‘http-parser’, and Mike Pall’s LuaJIT. Please consult the NOTICE file for licensing details.

Cryptography Notice
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country’s laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See http://www.wassenaar.org/ for more information.

The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with symmetric algorithms. The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.

### 如何在 Docker 容器内安装 wrk 性能测试工具 要在 Docker 容器内安装 `wrk` 性能测试工具,可以按照以下方法实现。以下是详细的说明: #### 方法一:构建自定义的 Docker 镜像 如果需要在一个全新的环境中集成 `wrk` 工具,则可以通过编写 Dockerfile 来创建一个包含 `wrk` 的镜像。 1. 创建一个新的目录用于存放 Docker 构建文件。 2. 编写 `Dockerfile` 文件如下所示: ```dockerfile FROM ubuntu:latest # 更新包管理器并安装必要的依赖项 RUN apt-get update && \ apt-get install -y git make gcc libssl-dev # 克隆 wrk 仓库到本地 RUN git clone https://github.com/wg/wrk.git /tmp/wrk # 进入克隆后的目录并编译 wrk WORKDIR /tmp/wrk RUN make # 将编译好的可执行文件复制到 PATH 中 RUN cp wrk /usr/local/bin/ # 清理临时文件 RUN rm -rf /tmp/wrk CMD ["wrk", "--help"] ``` 3. 执行命令以构建镜像: ```bash docker build -t my_wrk . ``` 此命令会成功创建名为 `my_wrk` 的镜像[^2]。 4. 启动容器并验证 `wrk` 是否可用: ```bash docker run --rm my_wrk wrk --version ``` 这一步将显示 `wrk` 版本号,表明其已正确安装。 --- #### 方法二:使用现成的官方或社区镜像 为了节省时间,可以直接拉取已经预装好 `wrk` 的公共镜像。例如,GitHub 上有许多开源项目提供了这样的镜像。 1. 查找合适的镜像地址(如 `williamyeh/wrk`),然后运行以下命令下载镜像: ```bash docker pull williamyeh/wrk ``` 2. 使用该镜像启动容器并运行简单的压力测试: ```bash docker run --rm williamyeh/wrk -t 10 -c 100 -d 30s http://example.com ``` 上述命令表示发起一次持续时间为 30 秒的压力测试,其中线程数为 10 (`-t`) 并发连接数为 100 (`-c`)。 --- #### 方法三:在现有容器中手动安装 wrk 对于某些情况下无法重新构建新镜像的情况,也可以进入正在运行中的容器内部完成手动生成操作。 1. 登录至目标容器终端环境: ```bash docker exec -it <container_id> bash ``` 2. 在容器内依次执行以下指令完成软件源更新以及所需组件获取过程: ```bash apt-get update && apt-get upgrade -y apt-get install -y git make gcc libssl-dev cd /tmp/ git clone https://github.com/wg/wrk.git cd wrk make mv wrk /usr/local/bin/ ``` 完成后即可调用 `wrk` 命令进行性能评估工作。 --- ### 关于 wrk 的特性及其应用场景 `wrk` 是一款高效的 HTTP 压力测试工具,具有高性能、灵活配置的特点[^4]。它可以轻松应对大规模并发请求的需求,并允许开发者借助 Lua 脚本来扩展功能范围。因此,在实际开发运维过程中非常适合用来衡量 Web 应用程序的服务质量水平。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值