關於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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM