性能是我们日常生活中经常接触到的一个词语,更好的性能意味着能给我们带来更好的用户体检。比如我们在购买手机、显卡、CPU等的时候,可能会更加的关注于这样指标,所以本篇就来做一个性能评测。
性能也一直是我们开发人员一直追求的一个目标,我们在做语言选择,平台选择,架构选择的过程中都需要在性能之间做衡量。
同样性能对 .NET Core 团队来说也是至关重要的,一项新技术的诞生,除了对生产力的提高,还有技术团队对性能的追求。
今天,我们就来做一个对比测试,来看看微软的这样新技术性能到底怎么样,俗话说的好:“是骡子是马,拉出来溜溜”。
下面让我开始吧。
在测试之前,我们必须要明确我们本次测试想达到的一个目标。本次测试主要是测试应用程序的一个吞吐量。其中QPS,并发数,响应时间是我们衡量吞吐量的几个重要指标。
以下是本次对比测试的任务目标:
编号 | 对比方 | 系统环境 | 宿主环境 | 测试目标 |
---|---|---|---|---|
1 | ASP.NET Core vs ASP.NET Core |
Windows | Kestrel vs IIS |
相同平台不同宿主间性能差距 |
2 | ASP.NET Core vs ASP.NET |
Windows | IIS vs IIS |
相同平台相同宿主不同框架间性能差距 |
3 | ASP.NET Core vs ASP.NET |
Windows | Kestrel vs IIS |
相同平台不同宿主不同框架间性能差距 |
4 | ASP.NET Core vs Python Django |
Linux | Kestrel vs uwsgi |
相同平台不同语言不同宿主不同框架间性能差距 |
5 | ASP.NET Core vs Java Servlet |
Linux | Kestrel vs Tomcat |
相同平台不同语言不同宿主不同框架间性能差距 |
6-1 | ASP.NET Core vs NodeJS Express |
Linux | Kestrel vs self host |
相同平台不同语言不同宿主不同框架间性能差距 |
6-2 | ASP.NET Core vs NodeJS Koa |
Linux | Kestrel vs self host |
相同平台不同语言不同宿主不同框架间性能差距 |
工欲善其事,必先利其器。
首先我们需要一个压力测试工具,本次我们使用 wrk,有关于wrk的介绍和使用,请查看我的 这篇博客。
然后我们需要一个性能监控工具,因为wrk已经会给我们输出吞吐量相关指标,所以我们只需要一个监控CPU,内存等的工具即可。本次我们使用 Windows 自带的性能监视器。
Windows 性能监视器的打开方式:
开始-->运行-->perfmon
PS: 在下面的监视器图中如果你发现cpu并没有100%,那是因为使用的虚拟机占用了一部分cpu,所以计算方式应该是虚拟机的cpu使用量+物理机cpu使用量。
既然做测试,首先肯定是具有相同的运行环境,以下是本次测试使用到的软件和硬件环境。
名称 | 操作系统 | 职责 | CPU | 核心数 | 内存 |
---|---|---|---|---|---|
物理机器1 | Windows 10 RS1 | Web Server && 负载生成 | Intel Core i5-4590 | 4 | 16G |
虚拟机器2 | Ubuntu Server 16.04 | Web Server | Intel Core i5-4590 | 2 | 1G |
虚拟机器3 | Nano Server | Web Server | Intel Core i5-4590 | 2 | 1G |
其中 虚拟机器2
为 “物理机器1” 使用 win 10 的 Hyper-v 技术搭建的一个虚拟机,所以有几个指标对于本次测试至关重要。
虚拟机设置为了2个虚拟核心,以便于在压力测试的过程中利用到多核特性。其中的虚拟机保留百分比,需要设置为100%,来分配两个物理cpu所有资源给它。占综系统资源百分比设置为50,也就是说虚拟机最多利用本地50%的CPU资源,虚拟机限制设置为100。
AspNet 在 GitHub 有一个开源的性能测试项目叫benchmarks,之前新闻中23倍的性能也是出自于本测试项目, 为了客观,本次测试并不使用该项目,所有项目均我们自己新建,并且使用当前流行的框架,为了排除代码因素的干扰,我们使用最简单的 Hello World!。
如果你觉得本代码不够客观公正,欢迎在GitHub上Fork本项目,修改后给我提交PR,我会重新进行测试,并且更新本博客。
GitHub: https://github.com/yuleyule66/AspNetCoreBenchmarksCompare
wkr命令参数:
1 |
wrk -t <span class="hljs-number">2</span> -<span class="hljs-built_in">c</span> <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency http:<span class="hljs-comment">//xxx</span> |
因为已经分配了2个核心给虚拟机使用,所以开的是双线程。使用这个参数是我经过多次测试,得到的一个最佳的模拟效果。
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5000</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5000</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">5.49</span>ms <span class="hljs-number">21.72</span>ms <span class="hljs-number">358.18</span>ms <span class="hljs-number">98.99</span>% Req/Sec <span class="hljs-number">23.28</span>k <span class="hljs-number">1.98</span>k <span class="hljs-number">27.48</span>k <span class="hljs-number">92.13</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">0.00</span>us <span class="hljs-number">75</span>% <span class="hljs-number">6.87</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">12.76</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">28.58</span>ms <span class="hljs-number">913567</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">115.00</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">45636.43</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">5.74</span>MB |
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5001</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5001</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">5.30</span>ms <span class="hljs-number">5.81</span>ms <span class="hljs-number">22.24</span>ms <span class="hljs-number">76.75</span>% Req/Sec <span class="hljs-number">7.61</span>k <span class="hljs-number">455.21</span> <span class="hljs-number">8.12</span>k <span class="hljs-number">90.00</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">3.14</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">9.02</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">15.62</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">17.17</span>ms <span class="hljs-number">302880</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">44.77</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">15130.97</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">2.24</span>MB |
总结:
QPS(Kestrel):45636.43
QPS(IIS):15130.97
这个结果难免令人诧异,程序部署在IIS上和使用Kestrel竟然差别如此之大,我们知道实际上即便部署在IIS上,实际上内部还是调用的Kestrel,但是测试结果告诉了我们答案。可能是由于IIS进一步的http封装导致的吧,毕竟IIS提供了那么多的其他功能。
以下是Windows的性能监视器,两个的曲线图差不多我就放一个了:
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5001</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5001</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">5.30</span>ms <span class="hljs-number">5.81</span>ms <span class="hljs-number">22.24</span>ms <span class="hljs-number">76.75</span>% Req/Sec <span class="hljs-number">7.61</span>k <span class="hljs-number">455.21</span> <span class="hljs-number">8.12</span>k <span class="hljs-number">90.00</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">3.14</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">9.02</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">15.62</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">17.17</span>ms <span class="hljs-number">302880</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">44.77</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">15130.97</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">2.24</span>MB |
ASP.NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:10280</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:10280</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.94</span>ms <span class="hljs-number">5.58</span>ms <span class="hljs-number">22.82</span>ms <span class="hljs-number">80.90</span>% Req/Sec <span class="hljs-number">9.10</span>k <span class="hljs-number">444.04</span> <span class="hljs-number">9.42</span>k <span class="hljs-number">95.00</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">3.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">10.10</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.57</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">16.45</span>ms <span class="hljs-number">362177</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.00</span>s, <span class="hljs-number">89.80</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">18104.50</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">4.49</span>MB |
总结:
QPS(ASP.NET Core + IIS):15130.97
QPS(ASP.NET + IIS):18104.50
看到这个结果的时候,其实我还是有一点小惊讶的,不仅仅是因为ASP.NET跑出了1.8K QPS这样的成绩,而是通过Stdev
可以看出,ASP.NET 在应对高请求高并发的时候,还是相当的稳定的。这个结果说明了,在同样Windows+IIS环境中,ASP.NET是具有优势和竞争力的,可以预见 ASP.NET 应该还不会淘汰的太快。
Windows性能图我就不上了,基本上和上面一样 CPU 100% 的使用率。
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5000</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:5000</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">5.49</span>ms <span class="hljs-number">21.72</span>ms <span class="hljs-number">358.18</span>ms <span class="hljs-number">98.99</span>% Req/Sec <span class="hljs-number">23.28</span>k <span class="hljs-number">1.98</span>k <span class="hljs-number">27.48</span>k <span class="hljs-number">92.13</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">0.00</span>us <span class="hljs-number">75</span>% <span class="hljs-number">6.87</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">12.76</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">28.58</span>ms <span class="hljs-number">913567</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">115.00</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">45636.43</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">5.74</span>MB |
ASP.NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:10280</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//localhost:10280</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.94</span>ms <span class="hljs-number">5.58</span>ms <span class="hljs-number">22.82</span>ms <span class="hljs-number">80.90</span>% Req/Sec <span class="hljs-number">9.10</span>k <span class="hljs-number">444.04</span> <span class="hljs-number">9.42</span>k <span class="hljs-number">95.00</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">3.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">10.10</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.57</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">16.45</span>ms <span class="hljs-number">362177</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.00</span>s, <span class="hljs-number">89.80</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">18104.50</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">4.49</span>MB |
总结
QPS(ASP.NET Core + Kestrel):45636.43
QPS(ASP.NET + IIS):18104.50
这个结果应该是在预料之中的,大概是3倍的性能差距吧。但是我觉得和之前微软宣传的23倍的性能,是有很大差距的。
注意,以下我们开始使用到虚拟机器2了,我们要在Windows性能监控器里面查看CPU使用率,还需要再添加2个计数器。
物理处理器 \Hyper-V Hypervisor Logical Processor(*) %Total Run Time
虚拟处理器 \Hyper-V Hypervisor Virtual Processor(*) %Guest Run Time
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.39</span>ms <span class="hljs-number">5.33</span>ms <span class="hljs-number">33.05</span>ms <span class="hljs-number">77.20</span>% Req/Sec <span class="hljs-number">13.43</span>k <span class="hljs-number">1.32</span>k <span class="hljs-number">17.95</span>k <span class="hljs-number">74.75</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">8.15</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.75</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">15.80</span>ms <span class="hljs-number">534787</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.01</span>s, <span class="hljs-number">67.32</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">26730.83</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.37</span>MB |
Python Django
服务端宿主运行命令:
1 |
sudo uwsgi --http :<span class="hljs-number">8000</span> --<span class="hljs-keyword">file</span> HelloWorldWebApp/wsgi.py --processes=<span class="hljs-number">2</span> --threads==<span class="hljs-number">2</span> --daemonize=/var/<span class="hljs-built_in">log</span>/django.<span class="hljs-built_in">log</span> |
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:8000</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:8000</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">23.40</span>ms <span class="hljs-number">12.23</span>ms <span class="hljs-number">78.13</span>ms <span class="hljs-number">74.81</span>% Req/Sec <span class="hljs-number">792.64</span> <span class="hljs-number">143.13</span> <span class="hljs-number">1.25</span>k <span class="hljs-number">67.10</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">21.16</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">31.25</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">38.26</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">53.75</span>ms <span class="hljs-number">31591</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.09</span>s, <span class="hljs-number">3.01</span>MB read Socket <span class="hljs-string">errors:</span> connect <span class="hljs-number">0</span>, read <span class="hljs-number">31591</span>, write <span class="hljs-number">0</span>, timeout <span class="hljs-number">0</span> Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">1572.64</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">153.67</span>KB |
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(Python Django + Kestrel ):1572.64
不知道是我运行的方式不对还是怎么,这个差距还是蛮大的,大概是17倍的差距。看来Python Web 在做针对于做大请求并发情况下,还是弱了一点。
C# 和 JAVA 一直是两大阵营的开发人员喜欢讨论的话题,为了避免有阵营偏见,JAVA的源代码是我委托我们一个JAVA同事编写的,并且委托由他部署的,并且已经交代了他避免使用jsp,由Servlet直接输出。
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.39</span>ms <span class="hljs-number">5.33</span>ms <span class="hljs-number">33.05</span>ms <span class="hljs-number">77.20</span>% Req/Sec <span class="hljs-number">13.43</span>k <span class="hljs-number">1.32</span>k <span class="hljs-number">17.95</span>k <span class="hljs-number">74.75</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">8.15</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.75</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">15.80</span>ms <span class="hljs-number">534787</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.01</span>s, <span class="hljs-number">67.32</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">26730.83</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.37</span>MB |
Java Servlet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:8080/j2eeWebApp/hello</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:8080/j2eeWebApp/hello</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.93</span>ms <span class="hljs-number">6.17</span>ms <span class="hljs-number">68.17</span>ms <span class="hljs-number">81.53</span>% Req/Sec <span class="hljs-number">9.22</span>k <span class="hljs-number">1.01</span>k <span class="hljs-number">14.06</span>k <span class="hljs-number">70.50</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">1.75</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">9.91</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">14.39</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">22.10</span>ms <span class="hljs-number">367733</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.05</span>s, <span class="hljs-number">93.70</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">18338.73</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">4.67</span>MB |
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(Java Servlet + Tomcat):18338.73
通过这个结果我们可以看出,在性能上 ASP.NET Core 已经超越了Java。不说太多了,怕被喷…
ASP.NET Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.39</span>ms <span class="hljs-number">5.33</span>ms <span class="hljs-number">33.05</span>ms <span class="hljs-number">77.20</span>% Req/Sec <span class="hljs-number">13.43</span>k <span class="hljs-number">1.32</span>k <span class="hljs-number">17.95</span>k <span class="hljs-number">74.75</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">8.15</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.75</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">15.80</span>ms <span class="hljs-number">534787</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.01</span>s, <span class="hljs-number">67.32</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">26730.83</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.37</span>MB |
NodeJS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">4.40</span>ms <span class="hljs-number">5.23</span>ms <span class="hljs-number">31.25</span>ms <span class="hljs-number">79.47</span>% Req/Sec <span class="hljs-number">10.32</span>k <span class="hljs-number">0.88</span>k <span class="hljs-number">11.37</span>k <span class="hljs-number">90.25</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">2.08</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">8.32</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">13.19</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">15.93</span>ms <span class="hljs-number">410902</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">61.13</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">20522.89</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.05</span>MB |
***************更新1:NodeJS 添加Web框架*******
Express框架,cluster模式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">30</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">30</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">1.97</span>ms <span class="hljs-number">1.45</span>ms <span class="hljs-number">32.23</span>ms <span class="hljs-number">83.97</span>% Req/Sec <span class="hljs-number">7.83</span>k <span class="hljs-number">0.90</span>k <span class="hljs-number">8.82</span>k <span class="hljs-number">91.50</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">2.50</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">3.50</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">6.00</span>ms <span class="hljs-number">311896</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.01</span>s, <span class="hljs-number">66.03</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">15583.99</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.30</span>MB |
Koa框架,cluster模式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">30</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:1337</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">30</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">1.74</span>ms <span class="hljs-number">0.86</span>ms <span class="hljs-number">13.59</span>ms <span class="hljs-number">86.65</span>% Req/Sec <span class="hljs-number">8.79</span>k <span class="hljs-number">804.39</span> <span class="hljs-number">9.98</span>k <span class="hljs-number">87.75</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">1.99</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">2.96</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">4.83</span>ms <span class="hljs-number">349856</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.02</span>s, <span class="hljs-number">53.38</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">17478.73</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">2.67</span>MB |
从测试结果可以看出,Koa框架性能略高于Express框架。
**************End***********
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(NodeJS):20522.89 (非cluster模式)
QPS(NodeJS Express):15583.99 (cluster模式)
QPS(NodeJS Koa):17478.73 (cluster模式)
这个结果着实让我吃了一惊,NodeJS性能竟然如此惊人,比JAVA要快10%。作为一个解释性语言这个性能可以说达到了极致,虽然在测试之前知道NodeJS采用的是异步IO,但还是被测试结果震惊了。
===========更新1=========
NodeJS 在加入了Web框架之后,性能仍然不弱。
不知道是不是因为NodeJS没有经过什么Web框架,直接输出的结果。所以我需要再加测一个ASP.NET Core 通过中间件直接输入结果的性能,这次我要使用微软的测试项目benchmarks。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">50</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/plaintext</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.48:5000/plaintext</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">50</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">3.69</span>ms <span class="hljs-number">5.03</span>ms <span class="hljs-number">18.30</span>ms <span class="hljs-number">80.38</span>% Req/Sec <span class="hljs-number">25.06</span>k <span class="hljs-number">4.14</span>k <span class="hljs-number">29.19</span>k <span class="hljs-number">83.33</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">806.00</span>us <span class="hljs-number">75</span>% <span class="hljs-number">6.82</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">12.62</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">15.63</span>ms <span class="hljs-number">1002476</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.10</span>s, <span class="hljs-number">126.20</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">49874.57</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">6.28</span>MB |
My God !!!
以下是测试结果的汇总统计:
编号 | 对比方 | 系统环境 | 宿主环境 | 测试结果(QPS) |
---|---|---|---|---|
1 | ASP.NET Core vs ASP.NET Core |
Windows | Kestrel vs IIS |
45.6k vs 15.2k |
2 | ASP.NET Core vs ASP.NET |
Windows | IIS vs IIS |
15.2k vs 18.2k |
3 | ASP.NET Core vs ASP.NET |
Windows | Kestrel vs IIS |
45.6k vs 18.2k |
4 | ASP.NET Core vs Python Django |
Linux | Kestrel vs uwsgi |
26.7k vs 1.57k |
5 | ASP.NET Core vs Java Servlet |
Linux | Kestrel vs Tomcat |
26.7k vs 18.3k |
6-1 | ASP.NET Core vs NodeJS Express |
Linux | Kestrel vs self host |
26.7k vs 15.6k |
6-2 | ASP.NET Core vs NodeJS Koa |
Linux | Kestrel vs self host |
26.7k vs 17.5k |
作为微软的下一代 ASP.NET 框架,ASP.NET Core没有让我们失望,通过本次测试,我们大概对ASP.NET Core的性能心里有底了。一个圈子的良好发展需要社区的共同参与,也希望大家共同为.NET Core社区贡献自己的力量,同时也希望看到本篇文章的CTOs们以后在平台和框架选择的过程中考虑一下ASP.NET Core,因为她真的很优秀。
如果你觉得本篇博客对您有帮助的话,感谢您的【推荐】,如果你对.NET Core感兴趣可以关注我,我会定期在博客分享关于.NET Core的学习心得。
========更新1 :2016-10-17 感谢园友“幻天芒” 关于NodeJS的贡献======
有园友反应NodeJS项目没有使用web mvc框架,所以特更新,同时感谢 "幻天芒" 在github向nodeJS项目提交的PR。
1、添加node 多核cpu cluster 模式
2、添加node koa
框架和express
框架测试
更新测试结果。
========更新2 :2016-10-19 添加ASP.NET Core 在Windows Nano Server的测试结果======
环境:虚拟机器3,和Linux硬件一样
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wrk -t <span class="hljs-number">2</span> -c <span class="hljs-number">30</span> -d <span class="hljs-number">20</span> --latency <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.52:8000</span> Running <span class="hljs-number">20</span>s test @ <span class="hljs-string">http:</span><span class="hljs-comment">//192.168.2.52:8000</span> <span class="hljs-number">2</span> threads and <span class="hljs-number">30</span> connections Thread Stats Avg Stdev Max +/- Stdev Latency <span class="hljs-number">1.08</span>ms <span class="hljs-number">709.98</span>us <span class="hljs-number">31.25</span>ms <span class="hljs-number">77.30</span>% Req/Sec <span class="hljs-number">13.98</span>k <span class="hljs-number">1.38</span>k <span class="hljs-number">15.80</span>k <span class="hljs-number">87.75</span>% Latency Distribution <span class="hljs-number">50</span>% <span class="hljs-number">1.00</span>ms <span class="hljs-number">75</span>% <span class="hljs-number">1.03</span>ms <span class="hljs-number">90</span>% <span class="hljs-number">2.00</span>ms <span class="hljs-number">99</span>% <span class="hljs-number">3.45</span>ms <span class="hljs-number">556354</span> requests <span class="hljs-keyword">in</span> <span class="hljs-number">20.03</span>s, <span class="hljs-number">70.04</span>MB read Requests/<span class="hljs-string">sec:</span> <span class="hljs-number">27780.50</span> Transfer/<span class="hljs-string">sec:</span> <span class="hljs-number">3.50</span>MB |
这个测试结果和微软的测试结果是一致的,Nano Server大概比在Linux上高出5-10%的性能。
========更新3 :2016-12-30 添加 WebListener 测试 ======
WebListener 是基于 Http.sys 实现的非跨平台只能运行于 Windows 的一个 web 服务器,其目的我觉得是为了替代iis的性能不足问题。
引用自QQ群 Lyrics:我的理解是这样的,Kestrel是跨平台的,定义了一套通用的 feature,然而目前在windows平台上,Kestrel所具备的feature 并没有 http.sys 提供的那么强大,为了使老系统能顺利迁移到core上面,微软不得已搞了一个能支持所有http.sys 的web server,就是weblistener, weblistener 能完整的利用 http.sys 的特性,在windows上功能完整。
测试结果:
Windows ASP.NET Core Kestrel :35.5k
Windows ASP.NET Core WebListener:27.9k
Kestrl 大概比 WebListener 高出 5-10%的性能。
本文地址:http://www.cnblogs.com/savorboard/p/dotnet-benchmarks.html
作者博客:Savorboard
欢迎转载,请在明显位置给出出处及链接