作者:link1st的开源项目
- Go 1.18 新特性,多模块工作区教程
- 介绍如何实现一个基于websocket分布式聊天(IM)系统
- Go 实现的压测工具
- Go实现双向链表
go 实现的压测工具,ab、locust、Jmeter压测工具介绍【单台机器100w连接压测实战】
License: Other
作者:link1st的开源项目
in readme.md page, about locust demo should be updated like this, or will throw exception task no found or class no found:
from locust import HttpUser, TaskSet, task
# 定义用户行为
class UserBehavior(TaskSet):
@task
def baidu_index(self):
self.client.get("/")
class WebsiteUser(HttpUser):
task = [UserBehavior] # 指向一个定义的用户行为类
min_wait = 3000 # 执行事务之间用户等待时间的下界(单位:毫秒)
max_wait = 6000 # 执行事务之间用户等待时间的上界(单位:毫秒)
如题,想做双向认证的 https 压测,没有看到可以指定 client 证书的参数。
文档有写可以压测http、webSocket请求、私有rpc调用, 可是并未找到具体是如何压测rpc的 请指教 谢谢~
go run main.go -c 10 -n 1 -u ws://127.0.0.1:4455/
开始启动 并发数:10 请求数:1 请求参数:
request:
url:ws://127.0.0.1:4455/
form:webSocket
method:GET
headers:map[]
verify:json
timeout:3s
debu:false
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
1s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│
2s│ 10│ 0│ 10│ 0.00│ 2.95│ 0.00│ 0.00│0:10
3s│ 10│ 0│ 10│ 0.00│ 2.95│ 0.00│ 0.00│0:10
4s│ 10│ 0│ 10│ 0.00│ 2.95│ 0.00│ 0.00│0:10
我的笔记本
OS: Ubuntu 20.04 LTS x86_64
CPU: Intel i5-10210U (8) @ 4.200GHz
error message
$ ./go-stress-testing-linux -c 1 -n 1 -p test.curl.txt
开始启动 并发数:1 请求数:1 请求参数:
request:
form:http
url:http://
method:POST
headers:map[authorization:eyJOIjoxNTkyNzA5MzA3LCJFIjoxNTkzNDAwNTA3LCJEIjoiMTU4NTYzMDMxOTIifS5ya2s4MHUvUnIzZUFneHVQalJCWE4xckxLTkRwVnVhL0I4dkFLNSt1TFBRPQ==]
data:
verify:statusCode
timeout:30s
debu:false
请求失败: Post "http:": http: no Host in request URL
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
0s│ 1│ 0│ 1│ 0.00│ 0.28│ 0.28│ 0.00│509:1
************************* 结果 stat ****************************
处理协程数量: 1
请求总数: 1 总请求时间: 0.001 秒 successNum: 0 failureNum: 1
************************* 结果 end ****************************
vi test.curl.txt
curl --request POST \
--url http://10.20.121.176:23025/path... \
--header 'authorization: joxNTkyNzA5MzA3LCJFIjoxNTkzNDAwNTA3LCJEIj...
从实际工作中,参数都不是固定的,请问是否有考虑支持,我昨天拿着你的代码,简单改了一下支持了随机参数去压测,但是只实现了http的方式的。而且跟现在功能很不兼容,暂时也不好提一个mr过来
@link1st 目前是不支持socket.io 的吧
你好,通过go夜读了解到这个项目,想问一下在压测过程中 如何尽量避免大量出现TIME_WAIT?
通过增大超时时间的设置么。
如果单测http请求,最大能达到多大的qps呢?
在实际应用中对于接口请求返回的校验。不同项目可能方式不一样
A: {"code":200,"msg":"Success","data":{}}
B: {"httpCode":200,"status":"Success","info":{}}
...
诸如此类,我目前想到的方法是直接添加校验模板,通过参数代入。
有没有更好的方案,对Go这块不是很熟悉
支持multipart/form-data 格式的表单提交吗?目前有个服务是通过multipartfile 来处理文件上传的。
我有个接口是使用 PUT 方法进行数据更新,我的 curl 文件大概是这样的:
curl -X PUT http://domain.com/path \
-H 'content-type: application/json' \
-H 'Authorization: Bearer ...' \
-H 'Accept: application/json' \
-H 'X-Language: zh_cn' \
-d '{"parts":1}'
但会被当作 POST 执行,看了下源码,在 curl_model.go 这个地方直接返回了 POST。
修改connectionMode = 2 后
connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or es
tablished connection failed because connected host has failed to respond.
exit status 2
我要测试5000个单机效果
创建到1560个websocket 并发测试,就报上面错误了
使用的是http短连接,我实际使用过程中出现了客户端大量time_wait问题。
-H 解析存在问题 无法解析token
添加以下参数
root soft nofile 1040000 <- repeat 1
root hard nofile 1040000
root soft nofile 1040000 <- repeat 1
root hard nproc 1040000
root soft core unlimited
root hard core unlimited
soft nofile 1040000 <- repeat 2
hard nofile 1040000
soft nofile 1040000 <- repeat 2
hard nproc 1040000
soft core unlimited
hard core unlimited
两处重复是否正确?
是否应该修改为
root soft nproc 1040000
root hard nproc 1040000
* soft nproc 1040000
* hard nproc 1040000
golang编程的视频课程,有兴趣可以加qq 752675460
-H参数增加Host参数后无效
比如TP50、TP90、TP99、TP999信息
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
1s│ 10│ 162│ 0│ 166.76│ 83.38│ 53.16│ 6.00│200:162
2s│ 10│ 324│ 0│ 164.51│ 102.15│ 52.10│ 6.08│200:324
3s│ 10│ 489│ 0│ 165.25│ 102.15│ 52.10│ 6.05│200:489
4s│ 10│ 662│ 0│ 166.60│ 102.15│ 51.64│ 6.00│200:662
5s│ 10│ 822│ 0│ 165.70│ 107.08│ 51.64│ 6.04│200:822
6s│ 10│ 991│ 0│ 166.29│ 107.08│ 51.18│ 6.01│200:991
6s│ 10│ 1000│ 0│ 166.32│ 107.08│ 51.18│ 6.01│200:1000
如题~
Line 13 in 166953c
这里应该是"github.com/link1st/go-stress-testing/model"吧
发现代码里写死了特定的验证逻辑,验证不了业务定义的code
我执行如下命令:.\go-stress-testing-win.exe -c 16 -n 1000 -u http://localhost/foo
其中会有一些错误提示影响查看统计数据:
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64169->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64174->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64173->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
128s│ 16│ 15758│ 67│ 146.94│21119.76│ 2.99│ 6.81│200:15758;509:67
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64186->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64202->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64203->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
ly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64210->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64213->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64214->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64219->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64226->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64220->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64227->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64228->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
请求失败: Get "http://localhost/foo": read tcp 127.0.0.1:64233->127.0.0.1:80: wsarecv: An existing connection was forcibly closed by the remote host.
平均耗时普遍比最短耗时还要小,是我对这个平均耗时理解有偏差吗, 它的具体意义 到底是什么呢?
使用压测时,使用命令“./go-stress-testing-linux -c 7500 -n 1 -u http://www.test1111.com”
此时会报错,
“请求失败: Get http://www.test1111.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
请求失败: Get http://www.test1111.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
请求失败: Get http://www.test1111.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
请求失败: Get http://www.test1111.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
请求失败: Get http://www.test1111.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers)”
➜ go-stress-testing git:(master) go run main.go -c 1 -n 100 -u https://www.baidu.com/
main.go:13:2: cannot find package "go-stress-testing/model" in any of:
/usr/local/go/src/go-stress-testing/model (from $GOROOT)
/Users/mac/go/src/go-stress-testing/model (from $GOPATH)
main.go:14:2: cannot find package "go-stress-testing/server" in any of:
/usr/local/go/src/go-stress-testing/server (from $GOROOT)
/Users/mac/go/src/go-stress-testing/server (from $GOPATH)
➜ go-stress-testing git:(master)
GetConn 建立连接失败 in... 0 websocket.Dial ws://localhost:8086/car/websocket?sceneId=5c861652e9cfa448f43290d1: bad status
GetConn 建立连接失败 in... 1 websocket.Dial ws://localhost:8086/car/websocket?sceneId=5c861652e9cfa448f43290d1: bad status
GetConn 建立连接失败 in... 2 websocket.Dial ws://localhost:8086/car/websocket?sceneId=5c861652e9cfa448f43290d1: bad status
GetConn 建立连接失败 3 websocket.Dial ws://localhost:8086/car/websocket?sceneId=5c861652e9cfa448f43290d1: bad status
what is problem?
如题
发现在dispose里只开了一个goroutine来收集数据,虽然有channel有1000的buffer,但是应该很快会被占满而使得发送请求阻塞吧
大佬您好,我没在压测结果中看到tps、延迟等指标,能帮提供下吗
context deadline exceeded (Client.Timeout exceeded while awaiting headers
$ cat go.mod
module go-stress-testing
go 1.14
require golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
感觉使用上比vendor方便点....
现在go mod的代理下载还是很快的..
Go 夜读诚挚的邀请 @link1st 你以 go-stress-testing
为基础,来到 Go 夜读给社区的小伙伴来一次在线分享。
你可以直接与我联系,WeChat: mai_yang
。
再次感谢~
请问最短耗时,最长耗时和平均响应时间的单位是什么?
I run the testing like: go-stress-testing-win.exe -c 100 -n 1000 -u http://10.40.5.155:8080 on windows box.
After "成功数" goes up to 65536, it raises error:
connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted.
After add one line to ""server/client/http_client.go" the issue is gone, plz check.
check code here --> req, err := http.NewRequest(method, url, body)
add line-> req.Close = true
在使用中发现,在Header中设置Host 不能争取的在请求中设置,经过研究net/http包和相关文档发现,Host 现在不在Header 中设置,这样不能保证工具能够对所有情况进行压测。已提交pr进行修改。
[1] https://blog.csdn.net/yuanlaidewo000/article/details/93750653
[2] https://github.com/golang/go/blob/master/src/net/http/request.go
postman导出的curl请求代码无法用,测试了后才发现是curl格式你好像只支持浏览器复制的curl格式,
建议兼容postman导出的curl格式,谢谢
提示不是正确的http请求
在同一台机器上测试:
先起服务
go run tests/servers.go
后面测试:
[root@test-10 go-stress-testing]# go run main.go -c 100 -n 10000 -u http://127.0.0.1:8088/
开始启动 并发数:100 请求数:10000 请求参数:
request:
form:http
url:http://127.0.0.1:8088/
method:GET
headers:map[]
data:
verify:statusCode
timeout:30s
debug:false
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
1s│ 100│ 4846│ 0│ 6372.45│ 40.35│ 1.25│ 15.69│200:4846
2s│ 100│ 10022│ 0│ 6510.04│ 40.35│ 0.98│ 15.36│200:10022
3s│ 100│ 14961│ 0│ 6448.37│ 40.35│ 0.98│ 15.51│200:14961
4s│ 100│ 19938│ 0│ 6451.98│ 40.35│ 0.98│ 15.50│200:19938
5s│ 100│ 24869│ 0│ 6443.08│ 40.35│ 0.98│ 15.52│200:24869
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
请求失败: Get http://127.0.0.1:8088/: dial tcp 127.0.0.1:8088: connect: cannot assign requested address
requestTimeFloat 小于1 的时候,int64(requestTimeFloat) 就会等于0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.