I have mysterious slow down of my web application.
I have discovered it on a View that is using many Ajax Json calls to MVC Controller to populate charts/table.
Everything works great after new worker is created (all data is populated every time < 1s), however as soon I will update/insert + SaveChanges on EF, I will be getting a horrible slow down (sometimes it can take 28s instead < 1s).
Basically everything is working fast until I will add/update a record anywhere in web app (it is a bigger app so there is no point to include code).
I am using
public class AspNetContext : DbContext
{
public AspNetContext() : base("DefaultConnection") {
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false; }
public class AspNetSqlContext : AspNetContext
{
public DbSet<Model.AspNetModels.AspNetUsers> AspNetUsers { get; set; }
}
}for DAL class.
Then Repo class:
//SinglepublicModel.AspNetModels.AspNetUsersAspNetUsersByMemberId(){using(AspNetContext.AspNetSqlContext context =newAspNetContext.AspNetSqlContext()){return context.AspNetUsers.Single(m => m.Id==MemberId);}}//CheckspublicboolCheckIfEmailFree(string email){using(AspNetContext.AspNetSqlContext context =newAspNetContext.AspNetSqlContext()){if(context.AspNetUsers.Any(m => m.Email== email)){returnfalse;}else{returntrue;}}}publicboolCheckIfUsernameFree(string username){using(AspNetContext.AspNetSqlContext context =newAspNetContext.AspNetSqlContext()){if(context.AspNetUsers.Any(m => m.UserName== username)){returnfalse;}else{returntrue;}}}}
Then in a controller I am declaring it as
private DAL.AspNet.AspNetUsersRepositoryAspNetUsersRepo;publicExampleController(){AspNetUsersRepo=newAspNetUsersRepository("null");}
That is a basically a pattern that I am using for all tables/models.
For last couple months everything was working just fine, unfortunately lately I start adding a new feature that shows data as charts / tables at one page.
I am using AJAX calls to JsonResult actions. Everything is very fast
Performance pre-EF update/save
Unfortunately after I update/save ANYTHING in DB I will get this performance:
Doesn't matter what is updated, it could a simply object that has just 2 records in table (2 columns, int & bool). As soon as EF hits it, the performance goes to drain.
I have tried to check what is causing it using dotTrace, it also shows a huge performance hit ( 947ms vs 8168ms after saving/updating to database).
7932ms from 8168ms is spent in clr.dll and therefore cannot say what is happening.
During debugging I have checked how much time it takes between actual call of the JsonResult action and the return of data and it takes ~ 5ms - 300ms.
Unfortunately it looks like something is causing a huge delay between AJAX => ??? => JsonResult action, as actions seems to be executed at the same speed.
Plus dotTrace also shows that most of the time is lost in clr.dll...