1

I have an ASP.NET MVC 4 site running on a Xeon E7540 @ 2 GHz 2 Cores, 8 GB Ram on a 64-bit Windows Server 2008 R2 Standard.

The application pool is using .NET 4.0 with Integrated Managed Pipeline Mode.

I've decorated my Index function with OutputCaching:

[OutputCache(CacheProfile = "ContentPageController.Index")]

and the following in the Web.config

<add name="ContentPageController.Index" duration="60" varyByParam="none" location="Server" />

The index action access a MS SQL database, I have SQL Profiler running on the DB server and I can see that if I refresh the same page from a browser within a 60 seconds period, the database is hit only once which indicates that the OutputCache is running.

However when I load test the site generating a rush of 1-50 users within 60 seconds (graph attached) the OutputCache fails to work almost immediately after the test starts, I can see in the SQL Profiler the queries hitting the database while I would have expected only the first request to hit the database.

About 15 seconds into the test the Webserver CPU started fluctuating between 85% and 100%, while the Private Memory of the worker process did not increase, staying below the 149MB mark having started at 147MB before the test.

I'm completely clueless, any idea what I should be looking for?

Many thanks!

blitz.io output showing that server starts timing out as it handles more than 18 concurrent users

Giuseppe Romagnuolo
  • 3,362
  • 2
  • 30
  • 38

1 Answers1

0

If you see multiple db hits and want to prevent this (e.g. run only once and cache) you would have to synchronize the access of this method (lock threads).

This ensures that only the first request hits the DB and all following requests could use the cache.

pseudo code:

if(!cache)
    lock start
       if(cache)return cache; // this will be hit when the 2nd thread passed the first if...
       cache = access db...
    lock end
return cache;

If this doesn't solve your issues you would have to investigate this a little bit further... What is the returned output of the site when the response times drop? Seems to return an error? You also have several timeouts...

What is the code which hits the database?

MichaC
  • 13,104
  • 2
  • 44
  • 56
  • Thanks @Ela but I believe the OutputCache attribute of MVC controls works differently, it is not the database result that it is cached but rather the entire ActionResult object, what you have illustrated seems more how to implement caching with something like memcached or radis, it is not the implementation I have adopted myself. – Giuseppe Romagnuolo Sep 24 '13 at 08:31
  • No I was talking about your issue. You said that "I can see in the SQL Profiler the queries hitting the database while I would have expected only the first request to hit the database" To prevent this, use cache locking before accessing the database... – MichaC Sep 24 '13 at 09:11