参考地址:https://github.com/link1st/go-stress-testing
安装golang环境

yum install -y golang

下载软件包

wget -q https://codeload.github.com/link1st/go-stress-testing/zip/master
unzip go-stress-testing-master.zip

下载执行命令

https://github.com/link1st/go-stress-testing/releases/download/v1.0.1/go-stress-testing-linux
chmod +x go-stress-testing-linux
cat >/root/go-stress-testing-master/build.sh <<EOF
#!/usr/bin/env bash
# 编译linux下可以执行文件
go build -o go-stress-testing-linux main.go
# 使用交叉编译 linux和windows版本可以执行的文件
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o go-stress-testing-linux main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o go-stress-testing-win.exe main.go
EOF

执行编译 

sh build.sh

命令参数说明

-c 表示并发数
-n 每个并发执行请求的次数,总请求的次数 = 并发数 * 每个并发执行请求的次数
-u 需要压测的地址

测试百度

./go-stress-testing-linux -c 1 -n 100 -u https://www.baidu.com/

开始启动  并发数:1 请求数:100 请求参数:
request:
form:http
url:https://www.baidu.com/
method:GET
headers:map[]
data:
verify:statusCode
timeout:3s
debu:false
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
1s│ 1│ 31│ 0│ 31.41│ 40.56│ 28.32│ 31.83│200:31
2s│ 1│ 63│ 0│ 31.79│ 40.56│ 27.70│ 31.45│200:63
3s│ 1│ 91│ 0│ 30.56│ 154.86│ 26.33│ 32.73│200:91
3s│ 1│ 100│ 0│ 30.74│ 154.86│ 26.33│ 32.53│200:100 ************************* 结果 stat ****************************
处理协程数量: 1
请求总数: 100 总请求时间: 3.263 秒 successNum: 100 failureNum: 0
************************* 结果 end ****************************

./go run main.go -c 1 -n 100 -u https://www.baidu.com/

─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
1s│ 1│ 29│ 0│ 30.46│ 40.27│ 27.73│ 32.83│200:29
2s│ 1│ 55│ 0│ 27.89│ 133.45│ 26.71│ 35.86│200:55
3s│ 1│ 86│ 0│ 28.80│ 133.45│ 25.89│ 34.73│200:86
4s│ 1│ 115│ 0│ 28.84│ 133.45│ 25.89│ 34.67│200:115
5s│ 1│ 146│ 0│ 29.35│ 133.45│ 25.89│ 34.07│200:146
6s│ 1│ 176│ 0│ 29.45│ 133.45│ 25.89│ 33.96│200:176
7s│ 1│ 199│ 0│ 28.62│ 184.13│ 25.25│ 34.94│200:199

 

参数解释:
耗时: 程序运行耗时。程序每秒钟输出一次压测结果
并发数: 并发数,启动的协程数
成功数: 压测中,请求成功的数量
失败数: 压测中,请求失败的数量
qps: 当前压测的QPS(每秒钟处理请求数量)
最长耗时: 压测中,单个请求最长的响应时长
最短耗时: 压测中,单个请求最短的响应时长
平均耗时: 压测中,单个请求平均的响应时长
错误码: 压测中,接口返回的 code码:返回次数的集合  

内核优化
修改程序最大打开文件数
被压测服务器需要保持100W长连接,客户和服务器端是通过socket通讯的,每个连接需要建立一个socket,程序需要保持100W长连接就需要单个程序能打开100W个文件句柄

vim /etc/security/limits.conf
这里需要把硬限制和软限制、root用户和所有用户都设置为 1040000
core 是限制内核文件的大小,这里设置为 unlimited
 添加以下参数

root soft nofile 1040000
root hard nofile 1040000 root soft nofile 1040000
root hard nproc 1040000 root soft core unlimited
root hard core unlimited * soft nofile 1040000
* hard nofile 1040000 * soft nofile 1040000
* hard nproc 1040000 * soft core unlimited
* hard core unlimited

注意:
/proc/sys/fs/file-max 表示系统级别的能够打开的文件句柄的数量,不能小于limits中设置的值
如果file-max的值小于limits设置的值会导致系统重启以后无法登录
# file-max 设置的值参考
cat /proc/sys/fs/file-max
12553500
修改以后重启服务器,ulimit -n 查看配置是否生效

最新文章

  1. 向 Git 服务器添加 SSH 公钥
  2. Oracle如何写出高效的SQL
  3. php通用安装程序,导入数据文件(.sql)的安装程序
  4. APP国际化
  5. 我的conky配置
  6. Python学习(18)面向对象
  7. git相关资料
  8. DOJO 八 event dojo/on
  9. Moving Tables
  10. 利用iframe技巧获取訪问者qq
  11. C#_FindWindow
  12. MySQL中group_concat()函数的排序方法
  13. MTBF
  14. 【重学计算机】操作系统D3章:存储管理
  15. java类的继承(基础)
  16. linux io的cfq代码理解
  17. linux mail操作
  18. SQL Server 数据库try catch 存储过程
  19. Eclipse “cannot be resolved to a type”
  20. 使用外部属性文件配置Bean以及Bean的生命周期方法

热门文章

  1. Google Code Jam 2020 Round1B Join the Ranks
  2. 15 自定义分页pagination全局组件
  3. 如何在本机启动两个tomcat
  4. 基础Html重点——防健忘
  5. if __name__ == ‘__main__‘
  6. 数据库增量备份,恢复innobackex
  7. 【新阁教育】基于EtherNet/IP实现欧姆龙NX系列PLC通信
  8. oracle之分层查询
  9. 学习go的一些笔记
  10. java之死锁