Go 和 Rust 的 Hello World Benchmark 测试结果令人好奇

43 天前
 oldcai

我在 Gin 、Actix 和 Axum 上使用 wrk 做了一些测试。Actix 和 Axum 使用 MiMalloc 作为分配器,发布配置文件包括以下设置:Lto=true 、opt-level=3 和 codegen-units=1 。

平均而言,Go 的延迟小于 1ms ,令人难以置信,而 Actix 的延迟要高得多,但吞吐量/rps 仍优于 Gin 。

我很好奇,为什么 Gin 的延迟如此之小,而 Qps 却远低于另外两个。


结果如下:

Gin (go):

> wrk -t8 -c100 -d30s http://localhost:3000/

Running 30s test @ http://localhost:3000/

8 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev

Latency 823.52us 1.16ms 25.86ms 88.29%

Req/Sec 22.94k 12.27k 118.70k 81.71%

5488891 requests in 30.07s, 680.50MB read

Requests/sec: 182521.70

Transfer/sec: 22.63MB


axum (rust):

> wrk -t8 -c100 -d30s http://localhost:3000/

Running 30s test @ http://localhost:3000/

8 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev

Latency 3.87ms 13.64ms 225.34ms 93.67%

Req/Sec 40.34k 23.31k 183.63k 73.83%

9516362 requests in 30.09s, 1.15GB read

Requests/sec: 316292.39

Transfer/sec: 39.21MB


actix (rust):

> wrk -t8 -c100 -d30s http://localhost:3000/

Running 30s test @ http://localhost:3000/

8 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev

Latency 34.43ms 66.10ms 541.12ms 86.22%

Req/Sec 42.77k 37.73k 214.31k 77.25%

9169105 requests in 30.09s, 769.50MB read

Requests/sec: 304762.55

Transfer/sec: 25.58MB

2418 次点击
所在节点    Go 编程语言
11 条回复
oldcai
43 天前
测试环境:
Mac Sonoma 14.4.1
MacBook Air M2
cyhulk
43 天前
看上去数据包大小有区别,可能应该是返回的 response 不一样,不同的框架可能默认返回不一致,这里有做对比吗
yooomu
43 天前
了解 go ,不懂 rust 。我猜测是框架的处理问题,算力一定的情况下,如果增大缓冲区,那么就能吞吐更多连接,那相应的单个连接的处理速度就会更慢,延迟就会更高
oldcai
43 天前
@cyhulk 看了下,response 基本一样,actix 的 response 头还少一行 content-type: text/plain; charset=utf-8
@yooomu 请问 Gin 的缓冲区怎样加?是监听 socket 的缓冲区吗?
cyhulk
43 天前
1.rust 无 gc
cyhulk
43 天前
@cyhulk #5 2.不同的框架实现不一样,axum 框架有他自己的特性,它的性能好,我理解是正常的
yaott2020
43 天前
代码贴一下?
ihciah
43 天前
actix 是每个 thread 起一个 runtime ,M2 的核心又是不对称的,所以延迟爆炸很正常。go 和 tokio(axum 用法)都是有任务窃取的,所以受影响不大。
codegenerator
43 天前
helloworld 能测出什么? go 跟 rust 一个主要区别是 gc
guonaihong
42 天前
你测试代码呢?可以把 fasthttp 也加进来一起测试下。
kxct
23 天前
盲猜 rust 没有开 nodelay ,或者框架自己有缓存,然后批量发送。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1030658

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX