mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-03 01:10:13 +08:00
commit
1bab6e6c2a
@ -1,67 +1,67 @@
|
|||||||
(翻译中by runningwater)Go vs .NET Core in terms of HTTP performance
|
论 HTTP 性能,Go 与 .NET Core 谁争雌雄
|
||||||
============================================================
|
============================================================
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Hello Friends!
|
朋友们,你们好!
|
||||||
|
|
||||||
Lately I’ve heard a lot of discussion around the new .NET Core and its performance especially on web servers.
|
近来,我听到了大量的关于新出的 .NET Core 和其性能的讨论,尤其在 Web 服务方面的讨论更甚。
|
||||||
|
|
||||||
I didn’t want to start comparing two different things, so I did patience for quite long for a more stable version.
|
因为是新出的,我不想立马就比较两个不同的东西,所以我耐心等待,想等发布更稳定的版本后再进行。
|
||||||
|
|
||||||
This Monday, Microsoft [announced the .NET Core version 2.0][7], so I feel ready to do it! Do you?
|
本周一,微软[发布 .NET Core 2.0 版本][7],因此,我准备开始。您们认为呢?
|
||||||
|
|
||||||
As we already mentioned, we will compare two identical things here, in terms of application, the expected response and the stability of their run times, so we will not try to put more things in the game like `JSON` or `XML`encoders and decoders, just a simple text message. To achieve a fair comparison we will use the [MVC architecture pattern][8] on both sides, Go and .NET Core.
|
如前面所提的,我们会比较他们相同的东西,比如应用程序、预期响应及运行时的稳定性,所以我们不会把像对 `JSON` 或者 `XML` 的编码、解码这些烦多的事情加入比较游戏中来,仅仅只会使用简单的文本消息。为了公平起见,我们会分别使用 Go 和 .NET Core 的[ MVC 架构模式][8]。
|
||||||
|
|
||||||
### Prerequisites
|
### 先决条件
|
||||||
|
|
||||||
[Go][9] (or Golang): is a [rapidly growing][10] open source programming language designed for building simple, fast, and reliable software.
|
[Go][9] (或者 Golang): 是一种[快速增长][10]的开源编程语言,旨在构建出简单、快捷和稳定可靠的应用软件。
|
||||||
|
|
||||||
There are not lot of web frameworks for Go with MVC support but, luckily for us Iris does the job.
|
用于支持 Go 语言的 MVC web 框架并不多,还好我们找到了 Iris ,可胜任此工作。
|
||||||
|
|
||||||
[Iris][11]: A fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.
|
[Iris][11]: 支持 Go 语言的快速、简单和高效的微型 Web 框架。它为您的下一代网站、API 或分布式应用程序奠定了精美的表现方式和易于使用的基础。
|
||||||
|
|
||||||
[C#][12]: is a general-purpose, object-oriented programming language. Its development team is led by [Anders Hejlsberg][13].
|
[C#][12]: 是一种通用的,面向对象的编程语言。其开发团队由 [Anders Hejlsberg][13] 领导。
|
||||||
|
|
||||||
[.NET Core][14]: Develop high performance applications in less time, on any platform.
|
[.NET Core][14]: 跨平台,可以在极少时间内开发出高性能的应用程序。
|
||||||
|
|
||||||
Download Go from [https://golang.org/dl][15] and .NET Core from [https://www.microsoft.com/net/core][16].
|
从 [https://golang.org/dl][15] 下载 Go ,从 [https://www.microsoft.com/net/core][16] 下载 .NET Core。
|
||||||
|
|
||||||
After you’ve download and install these, you will need Iris from Go’s side. Installation is very easy, just open your terminal and execute:
|
在下载和安装好这些软件后,还需要在 Go 端安装 Iris。安装很简单,仅仅只需要打开终端,然后执行如下语句:
|
||||||
|
|
||||||
```
|
```
|
||||||
go get -u github.com/kataras/iris
|
go get -u github.com/kataras/iris
|
||||||
```
|
```
|
||||||
|
|
||||||
### Benchmarking
|
### 基准
|
||||||
|
|
||||||
#### Hardware
|
#### 硬件
|
||||||
|
|
||||||
* Processor: Intel(R) Core(TM) i7–4710HQ CPU @ 2.50GHz 2.50GHz
|
* 处理器: Intel(R) Core(TM) i7–4710HQ CPU @ 2.50GHz 2.50GHz
|
||||||
|
|
||||||
* RAM: 8.00 GB
|
* 内存: 8.00 GB
|
||||||
|
|
||||||
#### Software
|
#### 软件
|
||||||
|
|
||||||
* OS: Microsoft Windows [Version 10.0.15063], power plan is “High performance”
|
* 操作系统: 微软 Windows [10.0.15063 版本], 电源计划设置为“高性能”
|
||||||
|
|
||||||
* HTTP Benchmark Tool: [https://github.com/codesenberg/bombardier][1], latest version 1.1
|
* HTTP 基准工具: [https://github.com/codesenberg/bombardier][1], 使用最新的 1.1 版本。
|
||||||
|
|
||||||
* .NET Core: [https://www.microsoft.com/net/core][2], latest version 2.0
|
* .NET Core: [https://www.microsoft.com/net/core][2], 使用最新的 2.0 版本。
|
||||||
|
|
||||||
* Iris: [https://github.com/kataras/iris][3], latest version 8.3 built with [go1.8.3][4]
|
* Iris: [https://github.com/kataras/iris][3], 使用基于 [Go 1.8.3][4] 构建的新新 8.3 版本。
|
||||||
|
|
||||||
Both of the applications will just return the text “value” on request path “api/values/{id}”.
|
两个应用程序都通过请求路径 “api/values/{id}” 返回文本“值”。
|
||||||
|
|
||||||
.NET Core MVC
|
.NET Core MVC
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
Logo designed by [Pablo Iglesias][5].
|
Logo 由 [Pablo Iglesias][5] 设计。
|
||||||
|
|
||||||
Created using `dotnet new webapi` . That `webapi`template will generate the code for you, including the `return “value” `on `GET `method requests.
|
可以使用 `dotnet new webapi` 命令创建项目,其 `webapi` 模板会为您生成代码,代码包含 `GET` 请求方法的 `返回“值”`。
|
||||||
|
|
||||||
_Source Code_
|
_源代码_
|
||||||
|
|
||||||
```
|
```
|
||||||
using System;
|
using System;
|
||||||
@ -166,7 +166,7 @@ namespace netcore_mvc.Controllers
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
_Start the .NET Core web server_
|
_运行 .NET Core web 服务项目_
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd netcore-mvc
|
$ cd netcore-mvc
|
||||||
@ -177,7 +177,7 @@ Now listening on: http://localhost:5000
|
|||||||
Application started. Press Ctrl+C to shut down.
|
Application started. Press Ctrl+C to shut down.
|
||||||
```
|
```
|
||||||
|
|
||||||
_Target and run the HTTP benchmark tool_
|
_运行和定位 HTTP 基准工具_
|
||||||
|
|
||||||
```
|
```
|
||||||
$ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
|
$ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
|
||||||
@ -197,9 +197,9 @@ Iris MVC
|
|||||||
|
|
||||||
|
|
||||||

|

|
||||||
Logo designed by [Santosh Anand][6].
|
Logo 由 [Santosh Anand][6] 设计。
|
||||||
|
|
||||||
_Source Code_
|
_源代码_
|
||||||
|
|
||||||
```
|
```
|
||||||
package main
|
package main
|
||||||
@ -243,7 +243,7 @@ func (vc *ValuesController) Delete() {}
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
_Start the Go web server_
|
_运行 Go web 服务项目_
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd iris-mvc
|
$ cd iris-mvc
|
||||||
@ -252,7 +252,7 @@ Now listening on: http://localhost:5000
|
|||||||
Application started. Press CTRL+C to shut down.
|
Application started. Press CTRL+C to shut down.
|
||||||
```
|
```
|
||||||
|
|
||||||
_Target and run the HTTP benchmark tool_
|
_运行和定位 HTTP 基准工具_
|
||||||
|
|
||||||
```
|
```
|
||||||
$ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
|
$ bombardier -c 125 -n 5000000 http://localhost:5000/api/values/5
|
||||||
@ -268,60 +268,60 @@ Statistics Avg Stdev Max
|
|||||||
Throughput: 19.65MB/s
|
Throughput: 19.65MB/s
|
||||||
```
|
```
|
||||||
|
|
||||||
For those who understand better by images, I did print my screen too!
|
想通过图片来理解的人,我也把我的屏幕截屏出来了!
|
||||||
|
|
||||||
Click [here][23] to see these screenshots.
|
请点击[这儿][23]可以看到这些屏幕快照。
|
||||||
|
|
||||||
#### Summary
|
#### 总结
|
||||||
|
|
||||||
* Time to complete the `5000000 requests` - smaller is better.
|
* 完成 `5000000 个请求`的时间 - 越短越好。
|
||||||
|
|
||||||
* Reqs/sec — bigger is better.
|
* 请求次数/每秒 - 越大越好。
|
||||||
|
|
||||||
* Latency — smaller is better
|
* 等待时间 — 越短越好。
|
||||||
|
|
||||||
* Throughput — bigger is better.
|
* 吞吐量 — 越大越好。
|
||||||
|
|
||||||
* Memory usage — smaller is better.
|
* 内存使用 — 越小越好。
|
||||||
|
|
||||||
* LOC (Lines Of Code) — smaller is better.
|
* LOC (代码行数) — 越少越好。
|
||||||
|
|
||||||
.NET Core MVC Application, written using 86 lines of code, ran for 2 minutes and 8 seconds serving 39311.56 requests per second within 3.19mslatency in average and 229.73ms max, the memory usage of all these was ~126MB (without the dotnet host).
|
.NET Core MVC 应用程序,使用 86 行代码,运行 2 分钟 8 秒,每秒接纳 39311.56 个请求,平均每秒有 3.19ms 等待,最大时到 229.73ms,内存使用大约为 126MB(不包括 dotnet 框架)。
|
||||||
|
|
||||||
Iris MVC Application, written using 27 lines of code, ran for 47 secondsserving 105643.71 requests per second within 1.18ms latency in average and 22.01ms max, the memory usage of all these was ~12MB.
|
Iris MVC 应用程序,使用 27 行代码,运行 47 秒,每秒接纳 105643.71 个请求,平均每秒有 1.18ms 等待,最大时到 22.01ms,内存使用大约为 12MB。
|
||||||
|
|
||||||
> There is also another benchmark with templates, scroll to the bottom.
|
> 还有另外一个模板的基准,滚动到底部。
|
||||||
|
|
||||||
Update 20 August 2017
|
2017 年 8 月 20 号更新
|
||||||
|
|
||||||
As [Josh Clark][24] and [Scott Hanselman][25] pointed out on this [re-twee][26]t , on .NET Core `Startup.cs` file the line with `services.AddMvc();` can be replaced with `services.AddMvcCore();` . I followed their helpful instructions and re-run the benchmarks. The article now contains the latest benchmark output for the .NET Core application with the change both Josh and Scott noted.
|
[Josh Clark] [24] 和 [Scott Hanselman] [25]在此 [tweet 评论] [26]上指出,.NET Core `Startup.cs` 文件中 `services.AddMvc();` 这行可以替换为 `services.AddMvcCore();`。我听从他们的意见,修改代码,重新运行基准,该文章的 .NET Core 应用程序的基准输出已经修改。
|
||||||
|
|
||||||
|
|
||||||
@topdawgevh @shanselman they also used AddMvc() instead of AddMvcCore()... doesn't one include more middleware?
|
@topdawgevh @shanselman 他们也在使用 AddMvc() 而不是 AddMvcCore() ...,难道都不包含中间件?
|
||||||
|
|
||||||
— @clarkis117
|
— @clarkis117
|
||||||
|
|
||||||
@clarkis117 @topdawgevh Cool @MakisMaropoulos we'll take a look. @ben_a_adams @davidfowl. Good learnings on how to make easier performant defaults.
|
@clarkis117 @topdawgevh Cool @MakisMaropoulos @ben_a_adams @davidfowl 我们来看看。认真学习下怎么使用更简单的性能默认值。
|
||||||
|
|
||||||
— @shanselman
|
— @shanselman
|
||||||
|
|
||||||
@shanselman @clarkis117 @topdawgevh @ben_a_adams @davidfowl @shanselman @ben_a_adams @davidfowl Thank you for your feedback! I did update the results, no difference. I'm open for any other suggestion
|
@shanselman @clarkis117 @topdawgevh @ben_a_adams @davidfowl @shanselman @ben_a_adams @davidfowl 谢谢您们的反馈意见。我已经修改,更新了结果,没什么不同。对其它的建议,我非常欢迎。
|
||||||
|
|
||||||
— @MakisMaropoulos
|
— @MakisMaropoulos
|
||||||
|
|
||||||
>It had a small difference but not as huge (8.91MB/s from 8.61MB/s)
|
>它有点稍微的不同但相差不大(从 8.61MB/s 到 8.91MB/s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
For those who want to compare with the standard `services.AddMvc(); `you can see the old output by pressing [here][27].
|
想要了解跟 `services.AddMvc()` 标准比较结果的,可以点击[这儿][27]。
|
||||||
|
|
||||||
* * *
|
* * *
|
||||||
|
|
||||||
### Can you stay a bit longer for one more?
|
### 想再多了解点儿吗?
|
||||||
|
|
||||||
Let’s run one more benchmark, spawn `1000000 requests` but this time we expect `HTML` generated by templates via the view engine.
|
我们再制定一个基准,产生 `1000000 次请求`,这次会通过视图引擎由模板生成 `HTML` 页面。
|
||||||
|
|
||||||
#### .NET Core MVC with Templates
|
#### .NET Core MVC 使用的模板
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -473,10 +473,12 @@ Views/Home/Index.cshtml
|
|||||||
|
|
||||||
These files are quite long to be shown in this article but you can view them at:
|
These files are quite long to be shown in this article but you can view them at:
|
||||||
https://github.com/kataras/iris/tree/master/_benchmarks/netcore-mvc-templates
|
https://github.com/kataras/iris/tree/master/_benchmarks/netcore-mvc-templates
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
_Start the .NET Core web server_
|
_运行 .NET Core 服务项目_
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd netcore-mvc-templates
|
$ cd netcore-mvc-templates
|
||||||
@ -487,7 +489,7 @@ Now listening on: http://localhost:5000
|
|||||||
Application started. Press Ctrl+C to shut down.
|
Application started. Press Ctrl+C to shut down.
|
||||||
```
|
```
|
||||||
|
|
||||||
_Target and run the HTTP benchmark tool_
|
_运行和定位 HTTP 基准工具_
|
||||||
|
|
||||||
```
|
```
|
||||||
Bombarding http://localhost:5000 with 1000000 requests using 125 connections
|
Bombarding http://localhost:5000 with 1000000 requests using 125 connections
|
||||||
@ -502,7 +504,7 @@ Statistics Avg Stdev Max
|
|||||||
Throughput: 89.03MB/s
|
Throughput: 89.03MB/s
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Iris MVC with Templates
|
#### Iris MVC 使用的模板
|
||||||
|
|
||||||
```
|
```
|
||||||
package controllers
|
package controllers
|
||||||
@ -615,11 +617,13 @@ views/index.html
|
|||||||
These files are quite long to be shown in this article but you can view them at:
|
These files are quite long to be shown in this article but you can view them at:
|
||||||
https://github.com/kataras/iris/tree/master/_benchmarks/iris-mvc-templates
|
https://github.com/kataras/iris/tree/master/_benchmarks/iris-mvc-templates
|
||||||
*/
|
*/
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_Start the Go web server_
|
_运行 Go 服务项目_
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd iris-mvc-templates
|
$ cd iris-mvc-templates
|
||||||
@ -629,7 +633,7 @@ Application started. Press CTRL+C to shut down.
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
_Target and run the HTTP benchmark tool_
|
_运行和定位 HTTP 基准工具_
|
||||||
|
|
||||||
```
|
```
|
||||||
Bombarding http://localhost:5000 with 1000000 requests using 125 connections
|
Bombarding http://localhost:5000 with 1000000 requests using 125 connections
|
||||||
@ -644,49 +648,50 @@ Statistics Avg Stdev Max
|
|||||||
Throughput: 192.51MB/s
|
Throughput: 192.51MB/s
|
||||||
```
|
```
|
||||||
|
|
||||||
Summary
|
总结
|
||||||
|
|
||||||
* Time to complete the `1000000 requests` — smaller is better.
|
* 完成 `1000000 个请求`的时间 - 越短越好。
|
||||||
|
|
||||||
* Reqs/sec — bigger is better.
|
* 请求次数/每秒 - 越大越好。
|
||||||
|
|
||||||
* Latency — smaller is better
|
* 等待时间 — 越短越好。
|
||||||
|
|
||||||
* Memory usage — smaller is better.
|
* 内存使用 — 越小越好。
|
||||||
|
|
||||||
* Throughput — bigger is better.
|
* 吞吐量 — 越大越好。
|
||||||
|
|
||||||
.NET Core MVC with Templates Application ran for 1 minute and 20 seconds serving 11738.60 requests per second with 89.03MB/s within 10.10ms latency in average and 1.97s max, the memory usage of all these was ~193MB (without the dotnet host).
|
|
||||||
|
|
||||||
Iris MVC with Templates Application ran for 37 seconds serving 26656.76requests per second with 192.51MB/s within 1.18ms latency in average and 22.52ms max, the memory usage of all these was ~17MB.
|
.NET Core MVC 模板应用程序,运行 1 分钟 20 秒,每秒接纳 11738.60 个请求,同时每秒生成 89.03M 页面,平均每秒有 10.10ms 等待,最大时到 1.97s,内存使用大约为 193MB(不包括 dotnet 框架)。
|
||||||
|
|
||||||
### What next?
|
Iris MVC 模板应用程序,运行 37 秒,每秒接纳 26656.76 个请求,同时每秒生成 192.51M 页面,平均每秒有 1.18ms 等待,最大时到 22.52ms,内存使用大约为 17MB。
|
||||||
|
|
||||||
Download the example source code from [there ][32]and run the same benchmarks from your machine, then come back here and share your results with the rest of us!
|
### 接下来呢?
|
||||||
|
|
||||||
For those who want to add other go or c# .net core web frameworks to the list please push a PR to the `_benchmarks` folder inside [this repository][33].
|
[这里][32]有上面所示的源代码,请下载下来,在您本地以同样的基准运行,然后把运行结果在这儿给大家分享。
|
||||||
|
|
||||||
I need to personally thanks the [dev.to][34] team for sharing my article at their twitter account, as well.
|
想添加 Go 或 C# .net core WEB 服务框架到列表的朋友请向[这个仓库][33]的 `_benchmarks ` 目录推送 PR。
|
||||||
|
|
||||||
Go vs .NET Core in terms of HTTP performance { author: @MakisMaropoulos } https://t.co/IXL5LSpnjX
|
我也需要亲自感谢下 [dev.to][34] 团队,感谢把我的这篇文章分享到他们的 Twitter 账户。
|
||||||
|
|
||||||
|
论 HTTP 性能,Go 与 .NET Core 谁争雌雄 {作者:@MakisMaropoulos} https://t.co/IXL5LSpnjX
|
||||||
|
|
||||||
— @ThePracticalDev
|
— @ThePracticalDev
|
||||||
|
|
||||||
|
|
||||||
Thank you all for the 100% green feedback, have fun!
|
感谢大家真心反馈,玩得开心!
|
||||||
|
|
||||||
#### Update: Monday, 21 August 2017
|
#### 更新 : 2017 年 8 月 21 ,周一
|
||||||
|
|
||||||
A lot of people reached me saying that want to see a new benchmarking article based on the .NET Core’s lower level Kestrel this time.
|
很多人联系我,希望看到一个基于 .NET Core 的较低级别 Kestrel 的基准测试文章。
|
||||||
|
|
||||||
So I did, follow the below link to learn the performance difference between Kestrel and Iris, it contains a sessions storage management benchmark too!
|
因此我完成了,请点击下面的链接来了解 Kestrel 和 Iris 之间的性能差异,它还包含一个会话存储管理基准!
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
via: https://hackernoon.com/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8
|
via: https://hackernoon.com/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8
|
||||||
|
|
||||||
作者:[ Gerasimos Maropoulos][a]
|
作者:[ Gerasimos Maropoulos][a]
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
译者:[runningwater](https://github.com/runningwater)
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user