2016-09-20 42 views
0

我有一种执行以下代码的方法:为什么我的方法在Azure中运行时会卡住?

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(); 

当我我的测试机(在Windows Server 2008 R2与SQL Server 2012)上运行它,它需要大约3秒即可完成。当我将它作为连接到Azure SQL DB的应用程序服务运行时,它在~4分钟后完成。应用服务器定价层是“标准:1大”和数据库服务器“S2”,所以我猜这些机器的性能不是问题。当然,两个数据库中的数据都是一样的。有没有人遇到类似的问题?

编辑 我不认为这是SQL服务器问题。我认为这是应用程序问题。我重写了代码,首先从DB获取所有数据,然后应用所有逻辑。这完成更快(30秒),但仍然不能与我自己的服务器的性能相媲美。任何想法都非常感谢。

+0

查询运行时,您需要查找等待状态 – TheGameiswar

+0

sys.dm_exec_requests – TheGameiswar

回答

0

这个问题是2倍,但最大的问题是Azure中应用程序和数据库实例的地理位置。下次在Azure中创建Web应用程序时,请确保Web应用程序和数据库服务器位于相同的区域(例如西欧)。要小心,因为Azure会默认设置随机的东西(在我的例子中是Central/West US/Brazil)。

相关问题