win10 使用 wrk 压测

win10 使用 wrk 压测

wrk 简述 (单机多核 CPU 压测工具)

wrk 是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue 等,通过多线程和事件模式,对目标机器产生大量的负载。

windows 使用 wrk 需要安装 适用于 Linux 的 Windows 子系统

这边安装的是wsl2 安装的是 ubuntu 24.04 系统
安装教程链接 https://blog.csdn.net/qq_41407687/article/details/142169822

wrk 安装

lutong@CHINAMI-JD614UJ:~$ sudo apt-get install wrk
## 输入wrk 出现 wrk 选项信息 证明已经安装成功了
lutong@CHINAMI-JD614UJ:~$ wrk
Usage: wrk <options> <url>
  Options:
    -c, --connections <N>  Connections to keep open
    -d, --duration    <T>  Duration of test
    -t, --threads     <N>  Number of threads to use

    -s, --script      <S>  Load Lua script file
    -H, --header      <H>  Add header to request
        --latency          Print latency statistics
        --timeout     <T>  Socket/request timeout
    -v, --version          Print version details

  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)
########翻译内容
用法:wrk<选项><url>
选项:
	-c、 --connections<N>要保持打开的连接
	-d、 --持续时间<T>测试持续时间
	-t、 --线程<N>要使用的线程数
	-s、 --script<s>加载Lua脚本文件
	-H、 --header<H>向请求添加标头
	--latency打印延迟统计信息
	--timeout<T>套接字/请求超时
	-v、 --version打印版本详细信息
	数字参数可以包括SI单位(1k、1M、1G)
	时间参数可以包括时间单位(2s、2m、2h)

测试本地地址 unable to connect to localhost:8080 Connection refused 问题

lutong@CHINAMI-JD614UJ:~$ wrk -t1 -d1s -c1 http://localhost:8080/hello
unable to connect to localhost:8080 Connection refused

解决方案链接 https://blog.csdn.net/qq_41407687/article/details/1421722201

压测测试

#我们使用一个线程 -t1  一秒 -d1s  两个连接并发 -c2 测试  http://172.31.80.1:8080/hello 接口
lutong@CHINAMI-JD614UJ:~$ wrk -t1 -d1s -c2 http://172.31.80.1:8080/hello
Running 1s test @ http://172.31.80.1:8080/hello
  1 threads and 2 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.53ms    1.12ms  14.43ms   92.31%
    Req/Sec     1.42k   184.21     1.69k    54.55%
  1557 requests in 1.10s, 206.79KB read
Requests/sec:   1416.02
Transfer/sec:    188.06KB

Running 1s test @ http://172.31.80.1:8080/hello  用例跑了1秒
  1 threads and 2 connections  一个线程 2个链接 
  Thread Stats 线程统计数据   Avg 平均值     Stdev 标准差     Max 最大值   +/- Stdev +/-正负一个标准差所占比例
    Latency    延迟           1.53ms        1.12ms           14.43ms      92.31%
    Req/Sec    请求大小/每秒   1.42k        184.21            1.69k       54.55%
  1557 requests in 1.10s, 206.79KB read   1.10s内有1557个请求,读取206.79KB
Requests/sec:   1416.02  每秒请求数:1416.02
Transfer/sec:    188.06KB 传输/秒:188.06KB

1.标准差 越大 系统性能波动较大
2.正负一个标准差所占比例 和 标准差 描述的意思差不多
3.我们主要关注 平均延迟 ,以及最大值延迟请求接口 中程序中哪个模块 性能耗时严重,还有每秒请求数量,
比如说 http://172.31.80.1:8080/hello 接口 这个 QPS(Query per second 每秒处理完的请求数) 能达到多少呢,每秒请求数:1416.02
4. -t 线程数量不要超过cpu 核数,避免压测把服务器打崩
5. 每台机器的 运行的 负载 和机器的配置不同 压测的 数据会有偏差

使用lua 脚本 配置 压测接口

lutong@CHINAMI-JD614UJ:~$ wrk -t1 -d30s -c2 -s ./geektime-basic-go/scripts/wrk/login.lua http://172.31.80.1:8080/users/login
Running 30s test @ http://172.31.80.1:8080/users/login
  1 threads and 2 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   141.13ms   23.60ms 404.49ms   97.90%
    Req/Sec    14.71      5.15    20.00     50.00%
  427 requests in 29.02s, 135.94KB read
  Socket errors: connect 0, read 0, write 0, timeout 2
Requests/sec:     14.72
Transfer/sec:      4.69KB

login lua 配置脚本

--login.lua
wrk.method="POST"
wrk.headers["Content-Type"] = "application/json"
-- 这个要改为你的注册的数据
wrk.body='{"email":"123@123qq.com", "password": "123456#"}'

使用 -s ./geektime-basic-go/scripts/wrk/login.lua 配置压测接口 请求 header body 参数
lua 脚本这方面也是初学者了解的不多

本文引用

性能测试工具 wrk使用教程https://www.cnblogs.com/quanxiaoha/p/10661650.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值