I'm hosting an app on Azure for testing purposes. However a lot of API calls are getting really slow even though performance does not seem to be maxed out at all. One API call that takes 170 ms locally with IIS Express and SQL Server Express takes a whooping 14485 ms on Azure. The testdata is exactly the same. There are a lot of includes going on but the data is needed and the query is even slower if the includes are not there.
Why is the query/API Call so much slower on Azure? I could understand it if performance was peeking but not a single parameter hits above 60%.
Code:
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();
Performance:
App Service:
Basic: 1 Medium
B2
2x cores
200 total ACU
3.5 GB memory
A-Series compute
Azure Standard database with 50 DTUs (S2).
Localhost request takes 170 ms
App Service request takes 14485 ms
Database call localhost:
Database call Azure Database: