保存下

This commit is contained in:
runningwater 2017-09-24 23:55:52 +08:00
parent 233e420fc5
commit 7a6050767c

View File

@ -1,67 +1,67 @@
(翻译中by runningwater)Go vs .NET Core in terms of HTTP performance
论 HTTP 性能Go 与 .NET Core 谁争雌雄
============================================================
![](https://cdn-images-1.medium.com/max/1200/1*60T60jSMO5yxUqJQmLZa4A.png)
Hello Friends!
朋友们,你们好!
Lately Ive heard a lot of discussion around the new .NET Core and its performance especially on web servers.
近来,我听到了大量的关于新出的 .NET Core 和其性能的讨论,尤其在 Web 服务方面的讨论更甚。
I didnt 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 youve download and install these, you will need Iris from Gos side. Installation is very easy, just open your terminal and execute:
在下载和安装好这些软件后,还需要在 Go 端安装 Iris。安装很简单仅仅只需要打开终端然后执行如下语句
```
go get -u github.com/kataras/iris
```
### Benchmarking
### 基准
#### Hardware
#### 硬件
* Processor: Intel(R) Core(TM) i74710HQ CPU @ 2.50GHz 2.50GHz
* 处理器: Intel(R) Core(TM) i74710HQ 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
![](https://cdn-images-1.medium.com/max/1600/1*v2VJL3-I3bLyuehntuqfng.png)
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;
@ -166,7 +166,7 @@ namespace netcore_mvc.Controllers
```
_Start the .NET Core web server_
_运行 .NET Core web 服务项目_
```
$ cd netcore-mvc
@ -177,7 +177,7 @@ Now listening on: http://localhost:5000
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
@ -197,9 +197,9 @@ Iris MVC
![](https://cdn-images-1.medium.com/max/1600/1*zf4BjL-7MQNJGikw5E-iNA.png)
Logo designed by [Santosh Anand][6].
Logo 由 [Santosh Anand][6] 设计。
_Source Code_
_源代码_
```
package main
@ -243,7 +243,7 @@ func (vc *ValuesController) Delete() {}
```
_Start the Go web server_
_运行 Go web 服务项目_
```
$ cd iris-mvc
@ -252,7 +252,7 @@ Now listening on: http://localhost:5000
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
@ -268,40 +268,40 @@ Statistics Avg Stdev Max
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/secbigger is better.
* 请求次数/每秒 - 越大越好。
* Latencysmaller is better
* 等待时间 — 越短越好。
* Throughputbigger is better.
* 吞吐量 — 越大越好。
* Memory usagesmaller 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 @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
@ -309,7 +309,7 @@ As [Josh Clark][24] and [Scott Hanselman][25] pointed out on this [re-twe
 — @MakisMaropoulos
>It had a small difference but not as huge (8.91MB/s from 8.61MB/s)
>它有点稍微的不同但相差不大(从 8.61MB/s 到 8.91MB/s)
@ -686,7 +686,7 @@ So I did, follow the below link to learn the performance difference between Kest
via: https://hackernoon.com/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8
作者:[ Gerasimos Maropoulos][a]
译者:[译者ID](https://github.com/译者ID)
译者:[runningwater](https://github.com/runningwater)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出