我正在尝试使用SQL Server Express和EF Core 3.1.3在ASP.NET Core 3.1中测量异步和同步的性能,并有两个函数完全相同,只是一个是异步的,一个是同步的:
[HttpGet("search/description/{searchString}")]
public async Task<ActionResult<IEnumerable<Products>>> SearchForProductsDescription(String searchString) {
return await _context.Products.Where(p => p.Description == searchString).ToListAsync();
}
还有同步版本:
return _context.Products.Where(p => p.Description == searchString).ToList();
我正在使用jmeter作为基准测试工具,同步函数比异步函数更快(如预期),但是当我增加jmeter中的线程数以便平均响应时间小于500ms时,同步代码仍然更快。我尝试在数据库中使用1000行和20000行,但仍然更快。我试图找到异步函数比同步函数更快的场景,但我遇到了麻烦,是否有什么我理解错了?
async
的优势。 - Stephen Cleary