Question

I am using redgate performance profiler to test my asp.net mvc 2 application. One of the things I found out was the XMLSerializer was taking too much of the CPU time so referring from this post. I changed it to where it uses XmlSerializerCache now.

Now the XmlSerializer issue is no longer there and I am profiling the application by simulating 80 users at the same time using the website with Jmeter. So now the top methods which take time are doing a FirstOrDefault() on some data I am pulling I will give example-

var values=(from c in DataContext.Table1
           join s in DataContext.Table2 on new { c.Id, c.date } 
            equals new { s.Id, s.date } into list
                          where c.Id== Id && c.date == date
                          from s in list.DefaultIfEmpty()
                          select new DayDTO()
                          {
                              Points = c.points,
                              Points1 = c.points1,
                              Points2 = c.points2,
                              Points3 = c.points3,
                              Points4 = c.points4
                          }).FirstOrDefault();

Can anyone suggest me what I can do to improve this ? The current times are 25 secs and 16 secs for the top 2 methods .. Is it just because I am simulating 80 user at the same time and there are some issues on database (sql server 2005) side like the table being too large and indexing etc...and I will look into that but currently I am trying to identify any issues you see with the code i.e. issues on C# side..

I would appreciate any help thanks !

Was it helpful?

Solution

This assumes that the top time is the "inclusive time", not the "exclusive time".

Inclusive time means that it includes any code called by the method, in this case the FirstOrDefault will execute the database call. Database calls are expensive in the context of latency, but the CPU thread is blocked and not using the CPU while waiting for the database call.

First you should ask yourself if this is a problem, it does not significantly affect throughput (assuming the database server can handle the load), but latency of your calls.

If this is a problem you need to speed up the actual SQL query. You should start SQL profiler, catch the actual question, then run it in SQL management studio. Look at the execution plan to see if the query is slower than expected and try to figure out why. If it is too slow you might check your indexing to start with.

OTHER TIPS

FirstOrDefault is probably being called out as the culprit simply because it's the method that is forcing enumeration in your case. If you threw in a .ToList() before it, you'd find the burden shift to .ToList().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top