BeetleX和Asp.net Core之webapi基础性能对比
本文主要针对BeetleX和Asp.net Core在基础WebApi功能性能对比
测试环境描述
硬件配置:E1230V2 16G内存 10Gb带宽
操作系统:Windows server 2008 R2 + .Net Core 2.15
测试工具:bombardier.exe
测试功能代码
为了确保测试的基础功能一致性,因此所有测试的url和请求输出内容都是一致。以下是针对BeetleX和Asp.net Core实现的WebaApi基础功能代码:
asp.net core mvc webapi
public class HomeController : Controller
{ public class JsonMessage
{
public string message { get; set; }
} public string plaintext()
{
return "Hello, World!";
} public object json()
{
return new JsonMessage { message = "Hello, World!" };
} public Employee Employee(int id)
{
Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
if (result == null)
result = new Employee();
return result;
} public object Orders(int id, string customerid, int index, int size)
{
Func<Order, bool> exp = o => (id == || o.EmployeeID == id)
&& (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
int count = DataHelper.Defalut.Orders.Count(exp);
if (size == )
size = ;
int pages = count / size;
if (count % size > )
pages++;
var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
return items;
}
}
beetlex webapi
[Controller(BaseUrl = "Home")]
public class Controller
{
public class JsonMessage
{
public string message { get; set; }
} public object plaintext()
{
return new TextResult("Hello, World!");
} public object json()
{
return new JsonResult(new JsonMessage { message = "Hello, World!" });
}
[Get(Route = "{id}")]
public object Employee(int id)
{
Employee result = DataHelper.Defalut.Employees.Find(e => e.EmployeeID == id);
if (result == null)
result = new Employee();
return new JsonResult(result);
}
[Get(Route = "{id}")]
public object Orders(int id, string customerid, int index, int size)
{
Func<Order, bool> exp = o => (id == || o.EmployeeID == id)
&& (string.IsNullOrEmpty(customerid) || o.CustomerID == customerid);
int count = DataHelper.Defalut.Orders.Count(exp);
if (size == )
size = ;
int pages = count / size;
if (count % size > )
pages++;
var items = DataHelper.Defalut.Orders.Where(exp).Skip(index * size).Take(size);
return new JsonResult(items); }
}
测试方式
通过bombardier.exe工具对两个服务开启100个连接并进行10000000次请求响应测试。测试的url如下:
/home/plaintext //返回一个简单的Hello, World!文本
/home/json //返回一个简单的Hello, World! json对象
/home/employee/3 //返回一个记员的json对象
/home/orders/3?index=0&size=5 //返回对应雇员订单列表的json对象
测试结果

从测试结果来看在最基本的内容输出时,主要涉及是网络处理这一块,在这方面Beetlex webapi有着绝对性能的优势,可以说比Asp.net Core webapi高出两倍之多。但随着加入一些json处理功能逻辑处理占用比率高后性能的差异就不是非常突出(也说明一点Newtonsoft.Json在处理json的时候没有.net coret自己的处理高效),不过即使在后面返回订单列表的时候还具备着一倍的性能优势在。为了更进一步测试BeetleX的处理能,已经把测试代码提交上TechEmpower/FrameworkBenchmarks,在一下轮测试应该能看到BeetleX的身影出现。
测试结果详细数据
asp core webapi
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/plaintext"
Bombarding http://192.168.2.18:8080/home/plaintext with 10000000 request(s) usin
g 100 connection(s)
10000000 / 10000000 [==========================================] 100.00% 2m14s
Done!
Statistics Avg Stdev Max
Reqs/sec 74691.94 3817.11 114988.50
Latency 1.33ms 488.74us 385.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 17.38MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/json"
Bombarding http://192.168.2.18:8080/home/json with 10000000 request(s) using 100
connection(s)
10000000 / 10000000 [==========================================] 100.00% 2m24s
Done!
Statistics Avg Stdev Max
Reqs/sec 69093.60 3770.80 83161.12
Latency 1.44ms 549.52us 385.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 17.13MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/employee/3" Bombarding http://192.168.2.18:8080/home/employee/3 with 10000000 request(s) usi
ng 100 connection(s)
10000000 / 10000000 [==========================================] 100.00% 3m15s
Done!
Statistics Avg Stdev Max
Reqs/sec 51224.14 2667.55 57796.82
Latency 1.95ms 637.04us 415.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 29.16MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:8080/home/orders/3?in
dex=0&size=5"
Bombarding http://192.168.2.18:8080/home/orders/3?index=0&size=5 with 10000000 r
equest(s) using 100 connection(s)
10000000 / 10000000 [===========================================] 100.00% 5m7s
Done!
Statistics Avg Stdev Max
Reqs/sec 32481.62 1568.13 36897.79
Latency 3.07ms 2.13ms 600.03ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 57.96MB/s
beetlex webapi
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/plaintext"
Bombarding http://192.168.2.18:9090/home/plaintext with 10000000 request(s) usin
g 100 connection(s)
10000000 / 10000000 [============================================] 100.00% 41s
Done!
Statistics Avg Stdev Max
Reqs/sec 239341.58 39420.70 261535.62
Latency 413.11us 1.02ms 396.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 41.56MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/json"
Bombarding http://192.168.2.18:9090/home/json with 10000000 request(s) using 100
connection(s)
10000000 / 10000000 [============================================] 100.00% 54s
Done!
Statistics Avg Stdev Max
Reqs/sec 184345.82 24707.02 208438.54
Latency 537.74us 1.07ms 395.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 34.64MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/employee/3" Bombarding http://192.168.2.18:9090/home/employee/3 with 10000000 request(s) usi
ng 100 connection(s)
10000000 / 10000000 [==========================================] 100.00% 1m12s
Done!
Statistics Avg Stdev Max
Reqs/sec 138350.49 15090.09 162791.05
Latency 717.80us 1.14ms 397.02ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 70.33MB/s
D:\>bombardier.exe -c 100 -n 10000000 "http://192.168.2.18:9090/home/orders/3?in
dex=0&size=5"
Bombarding http://192.168.2.18:9090/home/orders/3?index=0&size=5 with 10000000 r
equest(s) using 100 connection(s)
10000000 / 10000000 [==========================================] 100.00% 2m26s
Done!
Statistics Avg Stdev Max
Reqs/sec 68505.91 3209.14 72597.10
Latency 1.46ms 2.14ms 599.03ms
HTTP codes:
1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 118.06MB/s
完整测试代码
https://github.com/IKende/FastHttpApi/tree/master/PerformanceTest/Beetlex_VS_AspCore_webapi
BeetleX和Asp.net Core之webapi基础性能对比的更多相关文章
- 你所不知道的ASP.NET Core MVC/WebApi基础系列(一)
前言 最近发表的EF Core貌似有点多,可别误以为我只专攻EF Core哦,私下有时间也是一直在看ASP.NET Core的内容,所以后续会穿插讲EF Core和ASP.NET Core,别认为你会 ...
- 你所不知道的ASP.NET Core MVC/WebApi基础系列 (一)
转自博客:https://www.cnblogs.com/CreateMyself/p/9235968.html 前言 最近发表的EF Core貌似有点多,可别误以为我只专攻EF Core哦,私下有时 ...
- 你所不知道的ASP.NET Core MVC/WebApi基础系列(二)
前言 好久没冒泡了,算起来估计有快半年没更新博客了,估计是我第一次停更如此之久,人总有懒惰的时候,时间越长越懒惰,但是呢,不学又不行,持续的惰性是不行dei,要不然会被时光所抛弃,技术所淘汰,好吧,进 ...
- 你所不知道的ASP.NET Core MVC/WebApi基础系列 (二)
转自博客:https://www.cnblogs.com/CreateMyself/p/10604293.html 前言 本节内容,我们来讲讲.NET Core当中的模型绑定系统.模型绑定原理.自定义 ...
- ASP.NET Core MVC/WebAPi 模型绑定探索
前言 相信一直关注我的园友都知道,我写的博文都没有特别枯燥理论性的东西,主要是当每开启一门新的技术之旅时,刚开始就直接去看底层实现原理,第一会感觉索然无味,第二也不明白到底为何要这样做,所以只有当你用 ...
- ASP.NET Core MVC/WebAPi如何构建路由?
前言 本节我们来讲讲ASP.NET Core中的路由,在讲路由之前我们首先回顾下之前所讲在ASP.NET Core中的模型绑定这其中有一个问题是我在项目当中遇见的,我们下面首先来看看这个问题. 回顾A ...
- ASP.NET Core MVC/WebAPi 模型绑定探索 转载https://www.cnblogs.com/CreateMyself/p/6246977.html
前言 相信一直关注我的园友都知道,我写的博文都没有特别枯燥理论性的东西,主要是当每开启一门新的技术之旅时,刚开始就直接去看底层实现原理,第一会感觉索然无味,第二也不明白到底为何要这样做,所以只有当你用 ...
- 【转】ASP.NET Core MVC/WebAPi 模型绑定探索
前言 相信一直关注我的园友都知道,我写的博文都没有特别枯燥理论性的东西,主要是当每开启一门新的技术之旅时,刚开始就直接去看底层实现原理,第一会感觉索然无味,第二也不明白到底为何要这样做,所以只有当你用 ...
- 【译】ASP.NET Core 6 中的性能改进
原文 | Brennan Conroy 翻译 | 郑子铭 受到 Stephen Toub 关于 .NET 性能的博文的启发,我们正在写一篇类似的文章来强调 6.0 中对 ASP.NET Core 所做 ...
随机推荐
- java集合及其方法
1.集合框架 我们已经学习过使用数组来批量存储某一类数据: 但是,数组还是存在一些不足,比如长度不可变(建立对象的时候就已经定义好长度): 查找某一个数据时,要依靠索引值来遍历数组进行条件查找,数据量 ...
- Myeclipse使用git
推荐使用服务器:coding,coding的上传很稳定很快 怎么建仓库: coding 这个服务器呢有个很明显的东西就是太的语言可以是中文的, 点头标签的加号就能进行创建仓库了 点击新建就行了 点击这 ...
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...
- python库pandas简介
pandas是基于numpy的数据分析模块,提供了大量标准模型和高效操作大型数据集所需要的工具. pandas主要提供了3种数据结构:1.Series,带标签的一维数组:2.DataFrame,带标签 ...
- java 一维数组
数组的概念?有什么特点? 数组是指一组数据的集合,数组中的每个数据被称作元素.在数组中可以存放任意类型的元素,但同一个数组里存放的元素类型必须一致. 一维数组的定义格式? 数据类型[] 名称 = ...
- Tiny4412之按键驱动
一:按键驱动 按键驱动跟之前的LED,蜂鸣器的方法类似:通过底板,核心板我们可以看到按键的电路图: 通过电路图我们可以看出,当按键按下去为低电平,松开为高电平:所以我们要检测XEINT26的状态,通过 ...
- 二十、Hadoop学记笔记————Hive On Hbase
Hive架构图: 一般用户接口采用命令行操作, hive与hbase整合之后架构图: 使用场景 场景一:通过insert语句,将文件或者table中的内容加入到hive中,由于hive和hbase已经 ...
- Linux时间子系统之二:Alarm Timer
一.前言 严格来讲Alarm Timer也算POSIX Timer一部分,包含两种类型CLOCK_REALTIME_ALARM和CLOCK_BOOTTIME_ALARM.分别是在CLOCK_REALT ...
- CentOS-7修改主机名
本文由荒原之梦原创,原文链接:http://zhaokaifeng.com/?p=589 方法一(修改静态主机名): vi /etc/hostname 注:由于静态主机名是系统初始化时从/etc/ho ...
- 在 Docker 容器中运行应用程序
案例说明 运行 3 个容器,实现对网站的监控. 三个容器的说明: 容器 web: 创建自 nginx 映像,使用 80 端口,运行于后台,实现 web 服务. 容器 mailer: 该容器中运行一个 ...