我有一个执行以下代码的方法:
var subresulta1 = (from s in surveys
select new SurveyViewModel()
{
Id = s.Id,
Name = s.Name.Translation(Language.En),
IsActive = s.IsActive,
Locations = (from l in resulta.Select(a => a.Question.Location).Distinct()
select new LocationViewModel()
{
Id = l.Id,
Name = l.Name.Translation(Language.En),
Questions = (from q in resulta.Select(a => a.Question).Distinct()
where q.LocationId == l.Id
select new QuestionViewModel()
{
Text = q.QuestionText.Translation(Language.En),
Scores = (from a in resulta
where a.QuestionId == q.Id
select new ScoreViewModel()
{
Value = (int) a.Value,
PositionId = a.SurveyAnswers.PositionId,
Date = a.SurveyAnswers.CreatedDate,
Location = new LatLonViewModel()
{
Latitude = a.SurveyAnswers.Latitude,
Longitude = a.SurveyAnswers.Longitude
}
}).ToList()
}).ToList()
}).ToList()
}).ToList();
当我在测试计算机(带有SQL Server 2012的Windows Server 2008 R2)上运行它时,大约需要3秒钟才能完成。当我将其作为连接到Azure SQL DB的应用程序服务运行时,它会在约4分钟后完成。应用程序服务器的定价层为“标准:1大”,而数据库服务器为“ S2”,因此我认为这里的机器性能不是问题。当然,两个数据库中的数据是相同的。有没有人遇到过类似的问题?
编辑我不认为这是SQL Server问题。我认为这是应用程序问题。我重新编写了代码,以便首先从DB获取所有数据,然后应用所有逻辑。这样可以更快地完成(30秒),但仍然无法与我自己的服务器的性能相提并论。任何想法都受到高度赞赏。
这个问题有2个方面,但是最大的问题是Azure中应用程序和数据库实例的地理位置。下次在Azure中创建Web应用程序时,请确保Web应用程序和数据库服务器位于同一区域(例如,西欧)。请注意,因为Azure会尝试默认放置随机的内容(在我的情况下是美国中部/西部/巴西)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句