我正在使用实体框架 6.0.0 alpha1。
在我的 Asp.net MVC 应用程序中,我有两个控制器:
一种是没有异步的:
public ActionResult Index()
{
return View(db.Movie.ToList());
}
一种是异步的:
public async Task<ActionResult> Index()
{
var model = await db.Movie.ToListAsync();
return View(model);
}
我使用ab
工具来测试性能:
没有异步的结果:
Server Software: Microsoft-IIS/8.0
Server Hostname: localhost
Server Port: 60863
Document Path: /movies
Document Length: 5724 bytes
Concurrency Level: 10
Time taken for tests: 21.229 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 6071000 bytes
HTML transferred: 5724000 bytes
Requests per second: 47.11 [#/sec] (mean)
Time per request: 212.290 [ms] (mean)
Time per request: 21.229 [ms] (mean, across all concurrent requests)
Transfer rate: 279.27 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 4
Processing: 66 211 71.3 195 806
Waiting: 66 211 71.3 195 806
Total: 67 211 71.3 196 807
Percentage of the requests served within a certain time (ms)
50% 196
66% 223
75% 245
80% 260
90% 298
95% 334
98% 397
99% 461
100% 807 (longest request)
异步结果:
Concurrency Level: 10
Time taken for tests: 29.495 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 6071000 bytes
HTML transferred: 5724000 bytes
Requests per second: 33.90 [#/sec] (mean)
Time per request: 294.947 [ms] (mean)
Time per request: 29.495 [ms] (mean, across all concurrent requests)
Transfer rate: 201.01 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 2
Processing: 69 293 160.0 244 1546
Waiting: 69 293 160.0 244 1546
Total: 70 294 160.0 245 1547
Percentage of the requests served within a certain time (ms)
50% 245
66% 295
75% 343
80% 373
90% 507
95% 639
98% 772
99% 841
100% 1547 (longest request)
我的问题是为什么异步很慢?