OutputCache is an easy way to improve performance in ASP.NET <=4.6 MVC. We should apply this attributes for actions that are very expensive, but between the first request and the cache being created we could have a lot of concurrent requests - and will consume the server resources that we are trying to protect (Memory, CPU, I/O).
If multiples requests are from the same user, by default, aspnet serialize the requests as we can see in this link, The Downsides of ASP.NET Server Sate:
by default the ASP.NET pipeline will not process requests belonging to the same session concurrently. It serialises them, i.e. it queues them in the order that they were received so that they are processed serially rather than in parallel.
So, in order to simulate this situation, we need to create multiples requests (from different users). It can be done by creating request from more than one browser or using any kind of workload with multiple threads.
So, I'm trying to inherits from OutputCacheAttribute and create something like OutputCacheConcurrentRequestAttribute and serialize the requests from multiples users. Have anyone tried to do that?
The idea is to Thread.Sleep
all the subsequent requests for the same resource (Considering unique by the OutputCache properties and action) on OnActionExecuting
while the first request is not finished.
Looking the IL in ILSpy, some methods, which could help me in this job, are private and internal, like those:
Assembly: System.Web.Mvc
Namespace: System.Web.Mvc
class OutputCacheAttribute
{
private GetChildActionUniqueId
private BuildUniqueIdFromActionParameters
}
internal class DescriptorUtil
I'm trying to not duplicate the code and not use reflector (For performance reasons).
Have anyone faced the same problem?
Edit 1
After some research I have found that the MVC Donut caching have faced a lot of difficults to inhertis the OutputCacheAttribute and they have rewritten it completely:
In terms of implementing donut caching, hooking into the OutputCacheModule HttpModule would be very difficult/impossible, so instead we must rewrite the OutputCacheAttribute completely
It was much more easy to complete my idea using the DonutOutputCacheAttribute.