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 2020-09-30 14:01  Simple is best  阅读(548)  评论(1编辑  收藏  举报

导航