Simple is Best

思考 记录 ......

 

关于async对webapi性能影响的疑问(asp.net core3) -- 请教大神

都说action上使用异步能提升系统的整体性能,我就做了个简单的测试。

用了一个非常简单的写数据的方法(entityframework),一种是异步模式,一种是同步模式,测试下来,同步模式稍微块一点点。

难道说,只有比较耗时的方法,才适合采用用异步模式?

或者说我这测试有什么问题?

代码1

        public async Task<PostResult> EditLesson(LessonDto dto)
        {
            return await Task.Run(() =>
            {
                return lessonService.EditLesson(dto, UserInfo);
            });
        }

插入5000条数据的测试结果

复制代码
Status 200:    5000

RPS: 115.1 (requests/second)
Max: 2285ms
Min: 29ms
Avg: 83.5ms

  50%   below 74ms
  60%   below 78ms
  70%   below 83ms
  80%   below 91ms
  90%   below 105ms
  95%   below 121ms
  98%   below 145ms
  99%   below 167ms
99.9%   below 2265ms
复制代码

代码2

       public PostResult EditLesson2(LessonDto dto)
        {
                return lessonService.EditLesson(dto, UserInfo);
        }

测试结果

复制代码
Status 200:    5000

RPS: 149.5 (requests/second)
Max: 2793ms
Min: 18ms
Avg: 63.6ms

  50%   below 58ms
  60%   below 60ms
  70%   below 63ms
  80%   below 67ms
  90%   below 74ms
  95%   below 86ms
  98%   below 103ms
  99%   below 126ms
99.9%   below 2160ms
复制代码

 

posted on   Simple is best  阅读(564)  评论(1编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

统计

点击右上角即可分享
微信分享提示