2eNetWorX :: Development Community with Tutorial, Script, Code, Programming sections for Visual Basic, Active Server Pages and .Net Framework Developers.  

Improve Performance - Case Study :: Article - 2eNetWorX


This article explains how to build a Recordset caching system for your ASP web site to greatly improve the performance.

 
  2eNetWorX :: ASP, VB, Asp.Net, Vb.Net, C#, dotNet, .Net OpenSource Projects
MyDev What's New | Projects | Tutorials & Articles | Services | Stats | Contact Us
Guest-06165    /dev :: home :: articles :: Caching Recorsets  98 online visitors
Popular Projects

  • TableEditor
  • StatCounteX
  • 2eNetWorX/Dev
  • MiniSurvey
  • OpenForum
  • PowerTool
  • ShopEZ
  • Trans-It
  • HiLiteR
  • (View All Projects)


    Top 10

    » Contributions


    Tutorials & Articles

    » Recordset Cache
    » OpenSource
    » Statisticus
    » OpenCYA!


    Code Samples

    » Undocumented...
    » Ask For Login
    » DSN'less Connection
    » Who's Online?
    » (All Samples)


    Link Back



    Site Banner


  • Improving Database Performance by Caching serialized Recordsets

    by Hakan Eskici

    Part 1 - Key Features and Design
    Part 2 - Cache Storage and Implementation
    Part 3 - GetRecordset Function
    Part 4 - Cache Expiration and Removal
    Part 5 - Using the Cache Engine in your Projects
    Part 6 - Case Study and Final Words


    Step #2 (knowing when to call expiration methods) actually depends on your application design.

    For example, if your Customers table gets updated a few times a day; it would be wise to call ExpireTable "Customers" whenever you update your table.

    '...
    'You would have code above to initialize
    
    rs.AddNew
    rs("FirstName") = Request("txtFirstName")
    rs("LastName") = Request("txtLastName")
    '...
    rs.Update
    
    'Now it's a good time to expire your
    'Customers table:
    
    Dim MyCache
    Set MyCache = New DataCache
    
    MyCache.ExpireTable "Customers"
    
    

    There is a tradeoff between performance and freshness when we talk about caches. Our implementation is no different.

    If you don't expire your cache items when appropriate, you will come up with pages that display old data.

    If you expire your cache items too often (once in a few minutes for example), the performance may not satisfy you.

    It all depends on a few factors to know how often the cache should be expired:

    • Daily number of pageviews on database-bound pages
    • Complexity of the database queries
    • Frequency of database updates
    • Ability to know when a database gets updated
    Let's analyze the 2eNetWorX/dev forums case;
    • Thousands of pageviews on forum pages
    • Forum queries are complex and recursive (very slow)
    • Forum database is not updated very often
    • We know when the forum database is updated, it's when a visitor submits a new entry.
    For such a scenario, it would be very effective to expire the cache items only when a visitor submits a new entry to the forum. 99% of the time, forum data will be served from the cache.

    You can also put up a button somewhere in your administration pages to call RemoveAll() method on a periodic basis to make sure your all cache items get expired regularly.

    This caching technique is being used on 2eNetWorX/dev for a long time and provides impressive performance gain. Of course, the internal cache engine is more complex and have more features, but it's based on the ideas presented in this article.

    I have performed a few tests with a large database that contains hundreds of thousands of records (actually it's an old 2eNetWorX StatCounteX database).

    Here are the results:

      Time to get
    from DB
    Time to get
    from Cache
    Performance
    Improvement
    Query 1 406 ms 47 ms 800% (8x faster)
    Query 2 3,602 ms 62 ms 4,900% (42x faster)
    Query 3 8,062 ms 47 ms 17,200% (172x faster)

    Query 1: SELECT AVG(StatID) FROM Stats
    Query 2: SELECT * FROM TopPageViewsPerDay
    Query 3: SELECT * FROM TopIpsPerDay


    For a sneak preview of the internal 2eNetWorX cache engine, take a look at the cache reports.

    Feel free to contact us if you have questions, comments or new ideas related to the material presented here, or about purchasing the advanced version of the cache engine. Remember that we developers need feedback.

    Until the next article, take care.

    Download the source code for this article.



    < Previous Part: Using the Cache Engine in your Projects


    Hakan Eskici
    2eNetWorX OpenSource Projects
    http://www.2enetworx.com/dev



    Who's Online

     Bot: Google
     Bot: Msn
     (46) guests
     (50) repeated

    How is this done?


    Popular Web Sites

      FogBugz Hosting Plans
      SubVersion Hosting Plans
      SourceGear Vault
      Hosting Plans

      Note Thing - A Perfect
      To-Do List Software
      .net Localization
      components from SWBOX

      Mary Kay Products

    Admin's Toolbox

    Web Database Management
    Web Site Statistics
    Survey Manager
    Integrated forum for webpages
    OpenSource WebSite Framework


      privacy policy , license , disclaimer , © 2000-2004, 2eNetWorX.   [page generated in 31 ms.]