同一个代码,测试结果:
测试程序: 用 go gin 写了个最简单的 Web 服务
router.GET("/api/test", func(c *gin.Context) { c.IndentedJSON(200, gin.H{ "name": "alice", }) })
M1 Mac 本机压测过程:
nohup ./main > /dev/null 2>&1 &
ab -c 20 -n 10000 http://localhost:8080/api/tes
虚拟机 Linux 本机压测过程:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
nohup ./main > /dev/null 2>&1 &
ab -c 20 -n 10000 http://localhost:8080/api/tes
上面同样的程序,使用 SpringBoot 写了一个进行压测,在 M1 Mac 上的 QPS 和 Go 程序的结果几乎一样,CPU 使用情况也差不多。
1 jorneyr OP 压测命令是 ab -c 20 -n 10000 http://localhost:8080/api/test ,上面输入的时候少一个 t 。 |
![]() | 2 F281M6Dh8DXpD1g2 2022-12-13 17:43:31 +08:00 via iPhone ulimit 改了么 |
4 jorneyr OP 1. 修改 ulimit -n 5000 (在新的 tab 里看还是 256) 2. 启动 go 程序 5. 打开新 tab ,也执行 ulimit -n 5000 ,然后压测 QPS 还是 2000 左右。 |
5 jorneyr OP Linux 上 ulimit -n 结果上 1024 |
6 Fri 2022-12-13 18:10:47 +08:00 JDK 是适配 Apple Silicon 的吗? |
![]() | 8 xtinput 2022-12-13 21:07:31 +08:00 用 node.js 写了个简单的 http 服务,QPS 12000 以上 |
![]() | 9 xtinput 2022-12-13 21:10:33 +08:00 虚拟机里的 nginx 服务也是 QPS 12000 以上 |
10 jorneyr OP @xtinput 用 node.js 写了个简单的 http 服务,QPS 12000 以上 是 M1 吗?哪个版本的系统呢? 刚刚用 Nodejs express 写了个 Hello world ,QPS 在 1000 左右,QPS 只是 Go 和 Java 的一半。 |
![]() | 11 Zhuzhuchenyan 2022-12-13 22:54:07 +08:00 系统版本 12.6.1 ,用 nodejs v14.19.3 配合 express 写了一个最简单的 demo ,https://expressjs.com/zh-cn/starter/hello-world.html ab -c 20 -n 10000 http://localhost:3000 Requests per second: 6577.32 [#/sec] (mean) Time per request: 1.520 [ms] (mean) Time per request: 0.152 [ms] (mean, across all concurrent requests) Transfer rate: 1355.29 [Kbytes/sec] received wrk -c 32 -t 8 -d 5 http://localhost:3000 Requests/sec: 21436.36 Transfer/sec: 4.89MB 不过 apache benchmark 在测试过程中会有很诡异的卡住,wrk 无法复现这个问题 |
![]() | 13 xtinput 2022-12-14 08:31:12 +08:00 13.1 Requests per second: 14729.75 [#/sec] (mean) |
14 julyclyde 2022-12-14 09:32:15 +08:00 |
15 jorneyr OP 看来是我的环境问题了。 |
16 jorneyr OP @Zhuzhuchenyan wrk -c 32 -t 8 -d 5 http://localhost:3000 我这把 ab 换成了 wrk 后,QPS 能到 5000 ,要是 ulimit 等上去了,QPS 上万应该是比较容易的。 |
17 lscho 2022-12-14 11:19:06 +08:00 同款,12.6 ,php 起的服务 Requests per second: 17753.16 [#/sec] (mean) Time per request: 1.127 [ms] (mean) Time per request: 0.056 [ms] (mean, across all concurrent requests) Transfer rate: 4941.07 [Kbytes/sec] received |