ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)
来源:互联网 发布:石家庄盛光网络 编辑:程序博客网 时间:2024/06/05 20:28
前言
性能是我们日常生活中经常接触到的一个词语,更好的性能意味着能给我们带来更好的用户体检。比如我们在购买手机、显卡、CPU等的时候,可能会更加的关注于这样指标,所以本篇就来做一个性能评测。
性能也一直是我们开发人员一直追求的一个目标,我们在做语言选择,平台选择,架构选择的过程中都需要在性能之间做衡量。
同样性能对 .NET Core 团队来说也是至关重要的,一项新技术的诞生,除了对生产力的提高,还有技术团队对性能的追求。
今天,我们就来做一个对比测试,来看看微软的这样新技术性能到底怎么样,俗话说的好:“是骡子是马,拉出来溜溜”。
下面让我开始吧。
测试目标
在测试之前,我们必须要明确我们本次测试想达到的一个目标。本次测试主要是测试应用程序的一个吞吐量。其中QPS,并发数,响应时间是我们衡量吞吐量的几个重要指标。
以下是本次对比测试的任务目标:
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 ASP.NET Core
vs NodeJS
Linux Kestrel
vs self host
相同平台不同语言不同宿主不同框架间性能差距 测试工具
工欲善其事,必先利其器。
首先我们需要一个压力测试工具,本次我们使用 wrk,有关于wrk的介绍和使用,请查看我的 这篇博客。
然后我们需要一个性能监控工具,因为wrk已经会给我们输出吞吐量相关指标,所以我们只需要一个监控CPU,内存等的工具即可。本次我们使用 Windows 自带的性能监视器。
Windows 性能监视器的打开方式:
开始-->运行-->perfmon
PS: 在下面的监视器图中如果你发现cpu并没有100%,那是因为使用的虚拟机占用了一部分cpu,所以计算方式应该是虚拟机的cpu使用量+物理机cpu使用量。
环境准备
既然做测试,首先肯定是具有相同的运行环境,以下是本次测试使用到的软件和硬件环境。
软硬件环境
其中 虚拟机器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命令参数:
wrk -t 2 -c 50 -d 20 --latency http://xxx
因为已经分配了2个核心给虚拟机使用,所以开的是双线程。使用这个参数是我经过多次测试,得到的一个最佳的模拟效果。
1 - ASP.NET Core vs ASP.NET Core(Kestrel vs IIS)
ASP.NET Core
环境:物理机器1
OS:Windows 10 RS 1
Host:Kestrel
wrk -t 2 -c 50 -d 20 --latency http://localhost:5000Running 20s test @ http://localhost:5000 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.49ms 21.72ms 358.18ms 98.99% Req/Sec 23.28k 1.98k 27.48k 92.13% Latency Distribution 50% 0.00us 75% 6.87ms 90% 12.76ms 99% 28.58ms 913567 requests in 20.02s, 115.00MB readRequests/sec: 45636.43Transfer/sec: 5.74MB
ASP.NET Core
环境:物理机器1
OS:Windows 10 RS 1
Host:IIS 10.0
wrk -t 2 -c 50 -d 20 --latency http://localhost:5001Running 20s test @ http://localhost:5001 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.30ms 5.81ms 22.24ms 76.75% Req/Sec 7.61k 455.21 8.12k 90.00% Latency Distribution 50% 3.14ms 75% 9.02ms 90% 15.62ms 99% 17.17ms 302880 requests in 20.02s, 44.77MB readRequests/sec: 15130.97Transfer/sec: 2.24MB
总结:
QPS(Kestrel):45636.43
QPS(IIS):15130.97
这个结果难免令人诧异,程序部署在IIS上和使用Kestrel竟然差别如此之大,我们知道实际上即便部署在IIS上,实际上内部还是调用的Kestrel,但是测试结果告诉了我们答案。可能是由于IIS进一步的http封装导致的吧,毕竟IIS提供了那么多的其他功能。
以下是Windows的性能监视器,两个的曲线图差不多我就放一个了:
红色:CPU使用率
蓝色:内存使用率
2 - ASP.NET Core vs ASP.NET(IIS vs IIS)
ASP.NET Core
环境:物理机器1
OS:Windows 10 RS
Host:IIS
wrk -t 2 -c 50 -d 20 --latency http://localhost:5001Running 20s test @ http://localhost:5001 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.30ms 5.81ms 22.24ms 76.75% Req/Sec 7.61k 455.21 8.12k 90.00% Latency Distribution 50% 3.14ms 75% 9.02ms 90% 15.62ms 99% 17.17ms 302880 requests in 20.02s, 44.77MB readRequests/sec: 15130.97Transfer/sec: 2.24MB
ASP.NET
环境:物理机器1
OS:Windows 10 RS
Host:IIS
.NET Framework 4.6 + MVC5
wrk -t 2 -c 50 -d 20 --latency http://localhost:10280Running 20s test @ http://localhost:10280 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.94ms 5.58ms 22.82ms 80.90% Req/Sec 9.10k 444.04 9.42k 95.00% Latency Distribution 50% 3.00ms 75% 10.10ms 90% 13.57ms 99% 16.45ms 362177 requests in 20.00s, 89.80MB readRequests/sec: 18104.50Transfer/sec: 4.49MB
总结:
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% 的使用率。
3 - ASP.NET Core vs ASP.NET(Kestrel vs IIS)
ASP.NET Core
环境:物理机器1
OS:Windows 10 RS 1
Host:Kestrel
wrk -t 2 -c 50 -d 20 --latency http://localhost:5000Running 20s test @ http://localhost:5000 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.49ms 21.72ms 358.18ms 98.99% Req/Sec 23.28k 1.98k 27.48k 92.13% Latency Distribution 50% 0.00us 75% 6.87ms 90% 12.76ms 99% 28.58ms 913567 requests in 20.02s, 115.00MB readRequests/sec: 45636.43Transfer/sec: 5.74MB
ASP.NET
环境:物理机器1
OS:Windows 10 RS
Host:IIS
.NET Framework 4.6 + MVC5
wrk -t 2 -c 50 -d 20 --latency http://localhost:10280Running 20s test @ http://localhost:10280 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.94ms 5.58ms 22.82ms 80.90% Req/Sec 9.10k 444.04 9.42k 95.00% Latency Distribution 50% 3.00ms 75% 10.10ms 90% 13.57ms 99% 16.45ms 362177 requests in 20.00s, 89.80MB readRequests/sec: 18104.50Transfer/sec: 4.49MB
总结
QPS(ASP.NET Core + Kestrel):45636.43
QPS(ASP.NET + IIS):18104.50
这个结果应该是在预料之中的,大概是3倍的性能差距吧。但是我觉得和之前微软宣传的23倍的性能,是有很大差距的。
4 - ASP.NET Core vs Python Django
注意,以下我们开始使用到虚拟机器2了,我们要在Windows性能监控器里面查看CPU使用率,还需要再添加2个计数器。
物理处理器 \Hyper-V Hypervisor Logical Processor(*) \ %Total Run Time
虚拟处理器 \Hyper-V Hypervisor Virtual Processor(*) \ %Guest Run Time
ASP.NET Core
环境:虚拟机器2
OS:Linux
Host:Kestrel
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:5000/Running 20s test @ http://192.168.2.48:5000/ 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.39ms 5.33ms 33.05ms 77.20% Req/Sec 13.43k 1.32k 17.95k 74.75% Latency Distribution 50% 2.00ms 75% 8.15ms 90% 13.75ms 99% 15.80ms 534787 requests in 20.01s, 67.32MB readRequests/sec: 26730.83Transfer/sec: 3.37MB
Python Django
环境:虚拟机器2
OS:Linux
Host:uwsgi
Python 2.7.12 + Django 1.10.2
服务端宿主运行命令:
sudo uwsgi --http :8000 --file HelloWorldWebApp/wsgi.py --processes=2 --threads==2 --daemonize=/var/log/django.log
结果:
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:8000Running 20s test @ http://192.168.2.48:8000 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 23.40ms 12.23ms 78.13ms 74.81% Req/Sec 792.64 143.13 1.25k 67.10% Latency Distribution 50% 21.16ms 75% 31.25ms 90% 38.26ms 99% 53.75ms 31591 requests in 20.09s, 3.01MB read Socket errors: connect 0, read 31591, write 0, timeout 0Requests/sec: 1572.64Transfer/sec: 153.67KB
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(Python Django + Kestrel ):1572.64
不知道是我运行的方式不对还是怎么,这个差距还是蛮大的,大概是17倍的差距。看来Python Web 在做针对于做大请求并发情况下,还是弱了一点。
5 - ASP.NET Core vs Java Servlet
C# 和 JAVA 一直是两大阵营的开发人员喜欢讨论的话题,为了避免有阵营偏见,JAVA的源代码是我委托我们一个JAVA同事编写的,并且委托由他部署的,并且已经交代了他避免使用jsp,由Servlet直接输出。
ASP.NET Core
环境:虚拟机器2
OS:Linux
Host:Kestrel
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:5000/Running 20s test @ http://192.168.2.48:5000/ 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.39ms 5.33ms 33.05ms 77.20% Req/Sec 13.43k 1.32k 17.95k 74.75% Latency Distribution 50% 2.00ms 75% 8.15ms 90% 13.75ms 99% 15.80ms 534787 requests in 20.01s, 67.32MB readRequests/sec: 26730.83Transfer/sec: 3.37MB
Java Servlet
环境:虚拟机器2
OS:Linux
Host:Tomcat 7.0 + jdk 1.7
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:8080/j2eeWebApp/helloRunning 20s test @ http://192.168.2.48:8080/j2eeWebApp/hello 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.93ms 6.17ms 68.17ms 81.53% Req/Sec 9.22k 1.01k 14.06k 70.50% Latency Distribution 50% 1.75ms 75% 9.91ms 90% 14.39ms 99% 22.10ms 367733 requests in 20.05s, 93.70MB readRequests/sec: 18338.73Transfer/sec: 4.67MB
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(Java Servlet + Tomcat):18338.73
通过这个结果我们可以看出,在性能上 ASP.NET Core 已经超越了Java。不说太多了,怕被喷...
6 - ASP.NET Core vs NodeJS
ASP.NET Core
环境:虚拟机器2
OS:Linux
Host:Kestrel
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:5000/Running 20s test @ http://192.168.2.48:5000/ 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.39ms 5.33ms 33.05ms 77.20% Req/Sec 13.43k 1.32k 17.95k 74.75% Latency Distribution 50% 2.00ms 75% 8.15ms 90% 13.75ms 99% 15.80ms 534787 requests in 20.01s, 67.32MB readRequests/sec: 26730.83Transfer/sec: 3.37MB
NodeJS
环境:虚拟机器2
OS:Linux
Host:self host
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:1337Running 20s test @ http://192.168.2.48:1337 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.40ms 5.23ms 31.25ms 79.47% Req/Sec 10.32k 0.88k 11.37k 90.25% Latency Distribution 50% 2.08ms 75% 8.32ms 90% 13.19ms 99% 15.93ms 410902 requests in 20.02s, 61.13MB readRequests/sec: 20522.89Transfer/sec: 3.05MB
总结
QPS(ASP.NET Core + Kestrel):26730.83
QPS(NodeJS):20522.89
这个结果着实让我吃了一惊,NodeJS性能竟然如此惊人,比JAVA要快10%。作为一个解释性语言这个性能可以说达到了极致,虽然在测试之前知道NodeJS采用的是异步IO,但还是被测试结果震惊了。
不知道是不是因为NodeJS没有经过什么Web框架,直接输出的结果。所以我需要再加测一个ASP.NET Core 通过中间件直接输入结果的性能,这次我要使用微软的测试项目benchmarks。
wrk -t 2 -c 50 -d 20 --latency http://192.168.2.48:5000/plaintextRunning 20s test @ http://192.168.2.48:5000/plaintext 2 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.69ms 5.03ms 18.30ms 80.38% Req/Sec 25.06k 4.14k 29.19k 83.33% Latency Distribution 50% 806.00us 75% 6.82ms 90% 12.62ms 99% 15.63ms 1002476 requests in 20.10s, 126.20MB readRequests/sec: 49874.57Transfer/sec: 6.28MB
My God !!!
总结
以下是测试结果的汇总统计:
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 ASP.NET Core
vs NodeJS
Linux Kestrel
vs self host
26.7k vs 20.5k 作为微软的下一代 ASP.NET 框架,ASP.NET Core没有让我们失望,通过本次测试,我们大概对ASP.NET Core的性能心里有底了。一个圈子的良好发展需要社区的共同参与,也希望大家共同为.NET Core社区贡献自己的力量,同时也希望看到本篇文章的CTOs们以后在平台和框架选择的过程中考虑一下ASP.NET Core,因为她真的很优秀。
原文链接:http://www.cnblogs.com/savorboard/p/dotnet-benchmarks.html
.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注
- ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)
- Asp.net Core性能对比Asp.net .net Framework和Java Web Servlet
- ASP.NET和PHP性能对比
- ASP.NET Core 介绍
- ASP.NET Core
- Asp.net Core demo
- ASP.Net Core
- ASP.NET Core
- ASP.NET Core 日志
- ASP.NET Core
- ASP.NET Core
- Asp.Net Core-配置
- Asp.Net Core-身份验证
- ASP.NET Core
- asp.net.core教程
- ASP.NET Core
- ASP.NET Core
- ASP.NET Core
- ASP.NET Core MVC TagHelper实践HighchartsNET快速图表控件
- Autofac 之 基于 Castle DynamicProxy2 的 Interceptor 功能
- 微服务架构之外的选择——基于服务架构
- [ASP.NET Core] Middleware
- Visual Studio“15”进一步改善性能和易用性
- ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)
- 微软开源P语言,实现安全的异步事件驱动编程
- 在Linux和Windows的Docker容器中运行ASP.NET Core
- 在.NET Core中使用MEF
- 编程语言的发展趋势及未来方向(4):动态语言
- 初级排序
- 编程语言的发展趋势及未来方向(5):元编程
- 编程语言的发展趋势及未来方向(6):并发
- 编程语言的发展趋势及未来方向(7):总结