Categories
Bloggers
Blogs RSS feed

Performance Optimizations - Why Output Cache is Important

by Georgi Chokov

I’m starting a series of articles on performance optimizations in Sitefinity. In the first article I will explain what Output Cache is, how it works, what options Sitefinity offers and why does it matter.


ASP.Net is a great technology allowing us to easily create dynamic pages. Dynamic as opposed to static HTML means we can read data form database or other data source and display that data as it’s been altered. Also we can use controls that render different HTML based on settings or user input. ASP.Net and other systems build on top, such as Sitefinity, allow us to quickly build web applications and provide business solutions. However, all this comes at a price. Every single component in the execution chain is adding, more or less, to the CPU cost. Usually shorter execution chain means less CPU usage.


Request / Response lifecycle

I know most of you are very familiar with request / response lifecycle, but let me briefly describe to emphasize the importance of proper output caching. So, when an .aspx page is requested IIS passes the request to ASP.Net. ASP.Net creates new HttpContext object and invokes all HttpModules. Once all HttpModules are completed the context is passed to HttpHandler. In the case of .aspx page request, the handler creates new instance of Page object and calls ProcessRequestMain method of the page providing the current HttpContext. From that point on - the page lifecycle begins. Control hierarchy is instantiated, control state is loaded, events are fired, and then rendering process begins. As each control is created and added to the page’s controls collection, it starts a similar lifecycle. Some of the controls can make database calls, retrieve and process data or perform business logic before they render their HTML output. At render stage, the entire control hierarchy is traversed in the order it was created and each control writes it’s rendered HTML to the output stream, forming the response. After all controls render, the page and its control hierarchy is destroyed and the response is complete.


As you can see this is a lot of work that happens on every single request. Very often the content of pages don’t change from one request to another or they do rarely and then all this work is just wasted. If your site is not very busy, going through the entire lifecycle on each request might be perfectly OK. For busy sites, however, we definitely have to take action, as all this work is multiplied by the number of simultaneous requests. Note that by simultaneous requests I mean simultaneous for the entire site, not just the same page. By caching as many pages as possible, you leave more CPU time for the ones that really need it.


Make your website snappy with output cache

How does output cache work? When a URL is requested for the first time, the entire request / response lifecycle described above is processed, but right before the response is sent to the client - it gets stored in memory (Sitefinity also provides database cache storage). When the same URL is requested next time, instead of going through the same process, the response is retrieved from the cache and directly sent to the client.


It is perfect - almost. Once the page is cached it starts to work like static HTML. Very fast response, almost no server resource consumed. But there is a catch.


Cached pages are not dynamic anymore?

 What happens if data changes after the pages are cached? Or what if we want to display some information that is specific to the user making the request? There are different techniques such as expiration periods, cache dependencies and cache substitutions that allow you to control caching behavior and overcome these problems. How you choose techniques depends on what is more important to you, data actuality, performance, ease of use or effort involved.


What is next?

Expiration periods and cache dependencies allow you to control data actuality, while cache substitution allows you to inject content into already cached output and thus dynamically display information per request without losing much performance. Since in most cases Sitefinity handles cache dependencies automatically - while in Sitefinity 3.6 expiration is handled through GUI (making it dully obvious), the next posts will be about creating and using cache substitution controls. I will explain how Sitefinity extends ASP.Net cache substitution and how easy it is to turn any user control into a cache substitution.


I will also demonstrate how to create custom cache dependencies and will explain expiration settings as well as their effect on performance and memory usage.


The idea of this series is to help you make the right decisions and pull the optimal performance from your system by taking advantage of Sitefinity performance components.

32 comments

Leave a comment
  1. Jeremy Mar 09, 2009
    How about you (telerik) finish the great series of articles called theΒ DOCUMENTION before launching into yet another half finished series of articles.
  2. SAM Mar 09, 2009
    I concur..
  3. Michael Mar 10, 2009
    I agree, but am happy to see any documentation/development help we can get.
  4. Seth Mar 13, 2009
    Hi, while I agree that documentation does need to be finished I have been waiting patiently for cache substitution since version 3.0 and would LOVE to see these series of blog posts. Finally I can do substitution for my cart and and start caching some pages!!!
  5. Joel Mar 16, 2009
    This has been a point I have been interested in hearing Sitefinity focus on as well. While I agree with the above posters that documentation is important for the base product, I feel this is something I would like to hear more on from Sitefinity as well.
  6. Ken Dec 19, 2014
    +1 Jeremy -- more complete documentation, less fragmented blog articles
  7. Unikitty Jan 15, 2015
    I hope to meet this fine gentleman, Jeremy some day.  My whole team is a huge fan of you.
  8. Unikitty Apr 22, 2015
    Sitefinity has caused me massive therapy bills.
  9. Unikitty May 14, 2015
    http://www.quickmeme.com/img/d3/d36ad81bae0a8d69cd91f81065d8b0a19d9dfc1b63753093992282d6aa8b35dd.jpg
  10. Triple Rainbow May 14, 2015
    Boopshadoop!
  11. kwest May 14, 2015
    Triple Rainbow, wtf? Get outta here.
  12. Triple Rainbow May 14, 2015
    Just saying, I agree. If I enable output caching, can I still use Google?
  13. kwest May 14, 2015
    ugh
  14. Unikitty May 14, 2015
    wat
  15. Unikitty May 14, 2015
    This article is copywritted by Unikitty, LLC.
  16. Jeremy May 14, 2015
    Look guys, we don't need to troll Sitefinity. Just because their documentation sucks and they put very little effort into helping out the developers...you know what...nvm
  17. Unikitty May 14, 2015
    You are the voice of the people, Jeremy.
  18. twinklekitty May 14, 2015

    Where am I? Hello?

  19. A for real prince May 14, 2015

    Dear kwest,

    Permit me to inform you of my desire of developing output caching with you. I got your contact from the International web site directory. I prayed over it and selected your name among other names due to it's esteeming nature and the recommendations given to me as a reputable and trust worthy person I can do business with and by the recommendations of others on your output caching abilities. I am Wumi Abdul; the only Daughter of late Mr and Mrs George Abdul. My father was a very wealthy output cacher in Abidjan,the economic capital of Ivory Coast before he was poisoned to death by his business associates on one of their outing to discus on a business deal. When my mother died on the 21st October 1984, my father took me and my younger brother HASSAN special because we are motherless. Before the death of my father on 30th June 2002 in a private hospital here in Abidjan. He secretly called me on his bedside and told me that he has a sum of $12.500.000 (Twelve Million, five hundred thousand dollars) left in a suspense account in a local Bank here in Abidjan, that he used my name as his first Daughter for the next of kin in deposit of the fund. He also explained to me that it was because of this wealth and some huge amount of money his business associates supposed to balance his from the deal they had that he was poisoned by his business associates, that I should seek for a God fearing foreign partner in a country of my choice where I will transfer this money and use it for investment purpose, (such as real estate management). Sir, we are honourably seeking your assistance in the following ways.1) To provide a Bank account where this money would be transferred to.2) To serve as the guardian of this since I am a girl of 26 years.Moreover Sir, we are willing to offer you 15% of the sum as compensation for effort input after the successful transfer of this fund to your designate account overseas. please feel free to contact ,me via this email address wumi1000abdul@yahoo.comAnticipating to hear from you soon. Thanks and God Bless. Best regards. Miss Wumi Abdul PLEASE FOR PRIVATE, SECURITY, AND CACHING REASONS,REPLY ME VIA EMAIL: wumi1000abdul@yahoo.com

  20. Lego May 14, 2015

    Dear Unikitty,

    Unikitty is a registered trademark (http://www.knoxpatents.com/Images/TrademarkSymbol.gif#.png) of Lego, Inc. Please refrain from all future references to the character known as Unikitty. She is ill-tempered and would not take kindly to your insults.

    Sincerely,

    Lego

  21. Unikitty May 14, 2015
    Business business business
  22. Unikitty May 14, 2015
    πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©
  23. kwest May 14, 2015

    Hey man, you can't just come in here and drop feces on a page and pretend you're a creative genius. I AM the creative genius.

  24. Telerik Admin May 14, 2015

    As an administrator, I'd like to remind everyone that this is pointless, since no one uses Telerik products and these comments won't be seen by anyone.

  25. Telerik Middle Manager May 14, 2015
    You're fired.
  26. Teh Rules May 14, 2015
    http://static3.fjcdn.com/thumbnails/comments/Rules+of+nature+_7363871fa741d29049be9260bbe02364.gif#.png
  27. Securitai May 14, 2015
    <script>Function disableclick(event)
    {
      if(event.button==2)
       {
         alert('secure');
         return false;    
       }
    }</script>
  28. Anon May 14, 2015
    LLLLeeeeeeeerrrrrrrrroooooooooooyyyyyyyyyyyyyyy!
  29. Jerry May 14, 2015
    Is this like Sitecore?
  30. 😈 May 14, 2015

    Dear Diary,

    Today I told a client to use Sitefinity and luled so much inside my head. Because I knew they could pay less and avoid a world of hurt. But I like to make people suffer. 

    Love,

    😈

  31. LateToTheParty May 15, 2015

    I upgrade the website was 1998 into the latest 2009.  I read you 2009 output caching. This I need to the purchase.  How many output cachings In the American dollars.

    I need today for be the good.  This the late projects on time.

  32. Keylo's mom. May 15, 2015

    Turd nuggets! 

    Leave a comment