我在 Azure 上托管了一个应用程序用于测试目的。然而,尽管性能似乎根本没有达到极限,但许多 API 调用变得非常缓慢。使用 IIS Express 和 SQL Server Express 的一次 API 调用在本地需要 170 毫秒,而在 Azure 上需要 14485 毫秒。测试数据完全相同。有很多包含正在进行,但需要数据,如果包含不存在,查询会更慢。
为什么 Azure 上的查询/API 调用如此之慢?如果性能在窥探,但没有一个参数达到 60% 以上,我可以理解。
代码:
var results = db.ElectoralDistrictResults
.AsNoTracking()
.Where(x => x.ElectoralDistrict.Code == addressViewModel.ElectoralDistrictCode)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.CountyResult.Election.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.CountyResult.Election.ElectionTurnout)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.CountyResult.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.CountyResult.ElectionTurnout)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.CountyResult.County)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ConstituencyResult.ElectionTurnout)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.ElectionTurnout)
.Include(x => x.MunicipalityElectoralDistrictResult.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.ElectionTurnout)
.Include(x => x.ElectionTurnout)
.Include(x => x.Votes.Select(y => y.Party))
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityResult.Municipality.County)
.Include(x => x.MunicipalityElectoralDistrictResult.MunicipalityElectoralDistrict)
.Include(x => x.ElectoralDistrict)
.ToList();
表现:
应用服务:
Basic: 1 Medium
B2
2x cores
200 total ACU
3.5 GB memory
A-Series compute
具有 50 个 DTU (S2) 的 Azure 标准数据库。
本地主机请求需要 170 毫秒
应用服务请求需要 14485 毫秒
数据库调用本地主机:
数据库调用 Azure 数据库: