V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
oldcai
V2EX  ›  Go 编程语言

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

  •  
  •   oldcai ·
    oldcai · 22 天前 · 2199 次点击

    我在 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

    11 条回复    2024-04-28 10:48:03 +08:00
    oldcai
        1
    oldcai  
    OP
       22 天前
    测试环境:
    Mac Sonoma 14.4.1
    MacBook Air M2
    cyhulk
        2
    cyhulk  
       22 天前
    看上去数据包大小有区别,可能应该是返回的 response 不一样,不同的框架可能默认返回不一致,这里有做对比吗
    yooomu
        3
    yooomu  
       22 天前
    了解 go ,不懂 rust 。我猜测是框架的处理问题,算力一定的情况下,如果增大缓冲区,那么就能吞吐更多连接,那相应的单个连接的处理速度就会更慢,延迟就会更高
    oldcai
        4
    oldcai  
    OP
       22 天前
    @cyhulk 看了下,response 基本一样,actix 的 response 头还少一行 content-type: text/plain; charset=utf-8
    @yooomu 请问 Gin 的缓冲区怎样加?是监听 socket 的缓冲区吗?
    cyhulk
        5
    cyhulk  
       22 天前
    1.rust 无 gc
    cyhulk
        6
    cyhulk  
       22 天前
    @cyhulk #5 2.不同的框架实现不一样,axum 框架有他自己的特性,它的性能好,我理解是正常的
    yaott2020
        7
    yaott2020  
       22 天前 via Android
    代码贴一下?
    ihciah
        8
    ihciah  
       22 天前 via iPhone   ❤️ 2
    actix 是每个 thread 起一个 runtime ,M2 的核心又是不对称的,所以延迟爆炸很正常。go 和 tokio(axum 用法)都是有任务窃取的,所以受影响不大。
    codegenerator
        9
    codegenerator  
       22 天前   ❤️ 1
    helloworld 能测出什么? go 跟 rust 一个主要区别是 gc
    guonaihong
        10
    guonaihong  
       21 天前
    你测试代码呢?可以把 fasthttp 也加进来一起测试下。
    kxct
        11
    kxct  
       3 天前
    盲猜 rust 没有开 nodelay ,或者框架自己有缓存,然后批量发送。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2243 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:19 · PVG 13:19 · LAX 22:19 · JFK 01:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.