【发布时间】:2014-05-30 19:20:24
【问题描述】:
我刚刚升级到 VS 2013 并且还启动了一个新的 MVC 项目,并且在我的本地 PC 上进行调试时,IIS 会在几分钟内面临 99% 的 CPU 使用率。 (在发布和调试模式下都发生)我刚刚意识到问题与 Linq Query 返回的行数成正比。如果我使用 Take(1) 或 Take(10) 就可以了。如果我使用 Take(100) 就会出现问题。
这是我的操作结果(私人信息已更改):
public ActionResult Summary(string daystoshow, DateTime? day = null)
{
int daysToShow = daystoshow.ToSafeInt();
if (daysToShow < 1) daysToShow = 2;
if (day == null) day = Convert.ToDateTime("4/14/2014");
SummaryViewModel m = new SummaryViewModel();
string warnings = "";
var ef1 = new carshowEntities();
DateTime dayAtMidnight = Convert.ToDateTime(((DateTime)day).AddDays(daysToShow).ToShortDateString());
var diplayItems = (from x in ef1.islands
join y in ef1.cars on x.serid equals y.serid where x.dt==12
join z in ef1.ITEMS on y.serviceno equals z.ITEMNO
join x2 in ef1.islands on x.serid equals x2.serid where x2.dt==8
join i in ef1.INVOICES on x.carStyle equals i.carStyle where i.STATUS==8
where x.LiscenceDate > day && x.LiscenceDate < dayAtMidnight
orderby x.LiscenceDate, y.serviceno, x.serid
select new ReturnedItem()
{
CarOrderDate = (DateTime)x.LiscenceDate,
serial = x.serid,
ItemCode = y.serviceno,
Description = z.Color,
DateSold = (DateTime)x2.LiscenceDate,
ID = i.IX_ID
}).Take(100).ToList();
m.daystoshow = daysToShow;
m.day = day;
m.diplayItems = diplayItems;
m.warnings = warnings;
return View(m);
}
我还没有找到任何其他描述这里确切情况的帖子。
1) 网站发布后,在服务器上运行良好。
2) 在调试模式下运行我的 MVC 项目时,CPU 使用率高达 99%。
3) 如果我在本地发布,问题不会发生。
4) 当在调试或发布模式下从 VS 运行时,IIS 和 IIS Express 都会发生这种情况。
5) 其他网站没有发生这种情况,目前只有这个项目。
6) 这是一个简单的项目,一个 actionresult,一个页面有一个大约 200 行的表,填充了一个 Linq 查询。
调试器有什么办法至少可以告诉我它在做什么?
编辑:
经过进一步调查,我注意到如果我等待 2 分钟,CPU 会从 IIS 中恢复过来,但是 Web 浏览器(Firefox 或 Chrome)会在另外 2 分钟内占用 99% 的 CPU。
【问题讨论】:
-
它是什么样的 linq?实体框架?是永远100% cpu吗?还是一段时间?
-
它在本地计算机上的发布模式下不这样做?
-
它确实在发布模式下完成。对不起,直到你问我才想尝试。我会编辑我的帖子。
-
你是在调试器下以发布模式运行的吗?即 F5 与 Ctrl-F5?
-
很奇怪。我什至不知道这个功能。但是,它似乎是一项允许浏览器在您更改代码时自行更新的功能。我的猜测是它可能与 Web Essentials 有关,如果你安装了它,它会大量使用浏览器链接。
标签: asp.net-mvc entity-framework linq-to-entities