I've come across a rather unique problem that I haven't seen before.
The customer has a application server and a database server. The application server (win 2008) runs a ASP.NET MVC 3 App. The database server (also Win 2008) runs SQL Server 2008.
Whenever a request to the database is made, CPU for w3wp.exe goes up to 50 - 80 % and network traffic reaches 2% (of 10 Gbps). This takes a minute or so after which the requested web page is displayed.
I checked the actual Linq execution time and it only takes a few milliseconds to get the data.
I hope some of the professionals here can shed some light on what's going on. Of course, it works on my machine.
update
Even a query executed from SQL Server Management Studio (on the app server) that retrieves 828 rows takes a full 12 seconds to complete... So I guess the problem is not the app but somewhere on the database server or the connection
update 2 Here's something interesting I found out.
This is the slow code:
MyAppDataContext DataContext = MyAppDataContext.CreateNewContext();
IEnumerable<Requests> Entities = DataContext.Requests;
using (profiler.Step("get data")) {
IEnumerable<Requests> dataset = from x in Entities
where x.ControleStatus == 4
orderby x.ID
select x;
}
But when I change IEnumerable to IQueryable, the code executes 10x faster:
MyAppDataContext DataContext = MyAppDataContext.CreateNewContext();
IQueryable<Requests> Entities = DataContext.Requests.AsQueryable();
using (profiler.Step("get data")) {
IQueryable<Requests> dataset = from x in Entities
where x.ControleStatus == 4
orderby x.ID
select x;
}
So my question is: what could be causing this big difference between IEnumerable and IQueryable ?