zoukankan      html  css  js  c++  java
  • Go vs .NET Core 2.1

    .NET Core 2.1 正式发布之际,微软团队在博客的中提到了 .NET Core 2.1 中的性能提升。这让我想起了去年 Go 语言 Iris MVC 框架作者做的 Go 与 .NET Core 2.0 之间的性能对比,当时的 Iris 在各个方面的表现都基本超出 .NET Core 至少 1 倍,测试结果在社区中引发了不小的讨论,事后,微软团队的成员与 Iris 的作者进行了亲切友好的会谈,并就 Web 框架性能调优相关方面展开了深入的讨论。现在 .NET Core 2.1 版本正式发布,让我们来看看现在的 .NET Core 性能到底如何。

    2018年8月1日更新:据热心网友测试,完全关闭 ASP.NET Core 的日志功能可以成吨提升性能,详情见评论区

    跑分仅供参考

    测试项目地址:https://github.com/zeekozhu/iris

    原文地址:https://hackernoon.com/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8

    硬件配置

    • 处理器: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz 2.50GHz
    • 内存容量: 16.00 GB

    软件版本

    本次测试分三轮进行。第一轮测试中,服务器只返回简单的纯文本。第二轮测试中,服务器需要响应渲染出来的 HTML 模板。第三轮测试中,服务器都使用低层 API 来处理请求,并响应简单的纯文本。

    响应简单文本内容

    为了避免特定格式(如,JSONXML)序列化以及编码带来的影响,所以这次测试中仅测试了对简单文本的响应速度与稳定性。为了公平起见,Go 与 .NET Core 都使用了日常开发中最常用的 MVC 模式。

    .NET Core MVC

    $ cd netcore-mvc
    $ dotnet run -c Release
    Hosting environment: Production
    Content root path: C:mygopathsrcgithub.comkatarasiris\_benchmarks
    etcore-mvc
    Now listening on: http://localhost:5000
    Now listening on: https://localhost:5001
    Application started. Press Ctrl+C to shut down.
    Application is shutting down...
    
    $ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
    Bombarding http://localhost:5000/api/values/5 with 5000000 request(s) using 125 connection(s)
     5000000 / 5000000 [================================================================================] 100.00% 2m16s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     36682.65    7344.86  125924.45
      Latency        3.40ms   449.42us   254.50ms
      HTTP codes:
        1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:     8.09MB/s
    

    Iris MVC

    $ cd iris-mvc
    $ go run main.go
    Now listening on: http://localhost:5000
    Application started. Press CTRL+C to shut down.
    
    $ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
    Bombarding http://localhost:5000/api/values/5 with 5000000 request(s) using 125 connection(s)
     5000000 / 5000000 [================================================================================] 100.00% 1m11s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     70416.19   10167.84   89850.59
      Latency        1.77ms    74.69us    31.50ms
      HTTP codes:
        1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:    13.09MB/s
    

    简单文本性能测试结果

    • 完成 5000000 请求 的时间 - 越小越好。
    • Reqs/sec - 越大越好。
    • Latency - 越小越好。
    • Throughput - 越大越好。

    .NET Core MVC 程序,使用了 2 分 16 秒完成了测试,平均每秒能够处理:36682.65 个请求,平均的响应延迟在 3.40ms 左右,最大延迟为 254.50ms

    Iris MVC 程序,使用了 1 分 11 秒完成了测试,平均每秒能够处理:70416.19 个请求,平均的响应延迟在 1.77ms 左右,最大延迟为 31.50ms

    MVC + Templates

    接下来就是 MVC 服务端模板渲染性能测试,在这个测试中,服务端程序一共需要处理 1000000 个请求,并响应通过视图引擎渲染出来的 HTML。

    .NET Core MVC with Templates

    $ cd netcore-mvc-templates
    $ dotnet run -c Release
    Hosting environment: Production
    Content root path: C:mygopathsrcgithub.comkatarasiris\_benchmarks
    etcore-mvc-templates
    Now listening on: http://localhost:5000
    Now listening on: https://localhost:5001
    Application started. Press Ctrl+C to shut down.
    Application is shutting down...
    
    $ bombardier -c 125 -n 1000000 http://localhost:5000
    Bombarding http://localhost:5000 with 1000000 request(s) using 125 connection(s)
     1000000 / 1000000 [=================================================================================] 100.00% 1m18s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     13043.07    4754.11  120734.38
      Latency        9.74ms     2.07ms   464.00ms
      HTTP codes:
        1xx - 0, 2xx - 1000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:    92.25MB/s
    

    Iris MVC with Templates

    $ cd iris-mvc-templates
    $ go run main.go
    Now listening on: http://localhost:5000
    Application started. Press CTRL+C to shut down.
    
    $ bombardier -c 125 -n 1000000 http://localhost:5000
    Bombarding http://localhost:5000 with 1000000 request(s) using 125 connection(s)
     1000000 / 1000000 [==================================================================================] 100.00% 37s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     26927.88    4174.31   33129.39
      Latency        4.64ms   206.76us    34.00ms
      HTTP codes:
        1xx - 0, 2xx - 1000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:   194.24MB/s
    

    视图性能测试结果

    • 完成 1000000 请求 的时间 - 越小越好。
    • Reqs/sec - 越大越好。
    • Latency - 越小越好。
    • Throughput - 越大越好。

    .NET Core MVC 程序,使用了 1 分 18 秒完成了测试,平均每秒能够处理:13043.07 个请求,平均的响应延迟在 9.74ms 左右,最大延迟为 464.00ms

    Iris MVC 程序,使用了 37 秒完成了测试,平均每秒能够处理:33129.39 个请求,平均的响应延迟在 4.64ms 左右,最大延迟为 34.00ms

    低层 API 简单文本性能测试

    在本次测试中,服务端程序需要处理 1000000 个请求,并返回一个简单的纯文本响应。.NET Core 不再使用 ASP.NET Core MVC,而是直接通过 Kestrel 处理请求,Iris 也会使用底层的 Handlers 来处理请求。

    .NET Core (Kestrel)

    $ cd netcore
    $ dotnet run -c Release
    Hosting environment: Production
    Content root path: C:mygopathsrcgithub.comkatarasiris\_benchmarks
    etcore
    Now listening on: http://localhost:5000
    Now listening on: https://localhost:5001
    Application started. Press Ctrl+C to shut down.
    
    $ bombardier -c 125 -n 1000000 http://localhost:5000/api/values/5
    Bombarding http://localhost:5000/api/values/5 with 1000000 request(s) using 125 connection(s)
     1000000 / 1000000 [==================================================================================] 100.00% 17s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     55937.72    4492.32   66770.94
      Latency        2.23ms   328.65us    87.00ms
      HTTP codes:
        1xx - 0, 2xx - 1000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:    10.13MB/s
    

    Iris

    $ cd iris
    $ go run main.go
    Now listening on: http://localhost:5000
    Application started. Press CTRL+C to shut down.
    
    $ bombardier -c 125 -n 1000000 http://localhost:5000/api/values/5
    Bombarding http://localhost:5000/api/values/5 with 1000000 request(s) using 125 connection(s)
     1000000 / 1000000 [==================================================================================] 100.00% 12s
    Done!
    Statistics        Avg      Stdev        Max
      Reqs/sec     80559.83    6029.77   92301.38
      Latency        1.55ms   185.02us    34.50ms
      HTTP codes:
        1xx - 0, 2xx - 1000000, 3xx - 0, 4xx - 0, 5xx - 0
        others - 0
      Throughput:    14.98MB/s
    

    低层 API 简单文本性能测试结果

    • 完成 1000000 请求 的时间 - 越小越好。
    • Reqs/sec - 越大越好。
    • Latency - 越小越好。
    • Throughput - 越大越好。

    .NET Core MVC 程序,使用了 17 秒完成了测试,平均每秒能够处理:55937.72 个请求,平均的响应延迟在 2.23ms 左右,最大延迟为 87.00ms

    Iris MVC 程序,使用了 12 秒完成了测试,平均每秒能够处理:80559.83 个请求,平均的响应延迟在 1.55ms 左右,最大延迟为 34.50ms

    总结

    尽管微软在发行说明中提到了 .NET Core 2.1 有较大幅度的性能提升,但是在我的测试结果中与去年 Iris 作者运行的测试结果相差并不是很大。如果你认为本文的测试代码有问题,欢迎在评论区指出。

  • 相关阅读:
    8.10
    今日头条笔试题 1~n的每个数,按字典序排完序后,第m个数是什么?
    Gym 100500B Conference Room(最小表示法,哈希)
    CodeForces 438D The Child and Sequence(线段树)
    UVALIVE 6905 Two Yachts(最小费用最大流)
    Gym Conference Room (最小表示法,哈希)
    hdu 2389 Rain on your Parade(二分图HK算法)
    Codeforces Fox And Dinner(最大流)
    zoj 3367 Counterfeit Money(dp)
    ZOJ3370. Radio Waves(2-sat)
  • 原文地址:https://www.cnblogs.com/JacZhu/p/9120817.html
Copyright © 2011-2022 走看看