Use Write Caching to Optimize High Volume Data Driven Applications
page 3 of 11
by Steven Smith
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 62573/ 78

Test: No Caching – Nothing but DB

I ran two separate tests of my application using Microsoft Application Center Test.  The test script simply loads a single page.  That page displays several advertisements, and some other data-driven information.  Without any caching, each page view involves five database calls:

1) Pull information about the page itself

2) Pull collection of ads to show (always 3 in this test)

3-5) Log one impression for each advertisement

The two test cases vary only in the location of the database.  In the first case, the web server and database (and test client) were all located on the same machine.  In the second case, the database was offloaded to a separate machine on the same LAN.  All of these tests involve a single user (1 browser connection), no delays or sleep time, 30 seconds of warm-up, and a 5 minute test period (see Figure 1).

Figure 1: ACT Test Settings

 

The results of the two tests were dramatically different.  I monitored the network during the tests, and it was nowhere near capacity, so I have to conclude that the difference in requests per second stems from the millisecond delays incurred by the network latency.  Figure 2 shows the two tests.  The blue line (1) represents the case where the database was on a separate server.  The magenta line (the much higher one) represents the case of everything on one box.  The requests per second include several image, CSS and JavaScript requests per page – actual ASP.NET page requests is actually 1/7th of the total requests per second.

Figure 2: No Caching; Comparing Local Database (Magenta) with Separate Database (Blue)

 

(ALIENSTEVE is the name of my AlienWare laptop.)

 

More Details

Test 1 (Blue) averaged 9.14 ASP.NET requests/second.  Test 2 averaged 84.15 ASP.NET requests/second.  For test 1, the web server’s CPU averaged just 12% -- obviously it wasn’t the bottleneck.  For test 2, the web server (also the db server in this case) CPU averaged 69% (still not maxed out, but a dramatic difference).  Average Time to Last Byte (TTLB) in Test 1 for each whole page was 103ms.  For Test 2 it was just 7ms.

Looking at the database, in Test 1, the remote database averaged 91.86 Batch Requests/sec.  In Test 2, the local database averaged 420.74 Batch Requests/sec.


View Entire Article

User Comments

Title: Modern SQL XML Support   
Name: Steve Smith
Date: 2008-08-08 2:33:41 PM
Comment:
Jason Follas posted recently on how to do the SQL XML work more efficiently in SQL 2005+:
http://jasonfollas.com/blog/archive/2008/06/19/coding-in-sql-server-an-evolution.aspx
Title: MSMQ   
Name: Derek
Date: 2008-01-14 9:37:07 AM
Comment:
Thanks for the article. Having some experience with MSMQ I can tell you it will probably perform well, but we've had a lot of issues with using it in a clustered environment. This is a well-known shortcoming of MSMQ.

We've gone to some 3rd party pub-sub solutions that work much more efficiently and work well in a clustered environment.
Title: Using a synchronized HashTable   
Name: Tim
Date: 2005-08-22 1:41:25 PM
Comment:
Also, how would this be affected by using Hashtable.Synchronized(...) to create the hashtable. It appears that automatically protects the hashtable's Add method and the indexing property Set accessor with a lock, which would protect you during writes.
Title: What about the code for updating the item in Cache?   
Name: Tim
Date: 2005-08-22 12:08:14 PM
Comment:
Can you show sample code for updating the item in Cache? For example, if item is added to cache with certain expiration, etc., when you update it, do you have to add it back with the same parameters, or do you just reference it like Cache[myitem] = updatedValue, and it will retain all previously set values...

Thanks
Title: Programmer   
Name: Microfolx
Date: 2005-05-21 10:33:19 AM
Comment:
This is a very nice site. Keep it up.
Title: Re: Consistency   
Name: Brett
Date: 2005-05-20 5:15:54 PM
Comment:
Nice article... I might consider trying normal XML writers rather than StringBuilder. Or even XML serialization. Probably slightly slower, but reduces errors.

On the point regarding charging for page views. I have two suggestions. One is to periodically reload the current click count from the database and not worry about being exact. Hey if they get 1 million or 1,005,000, does it really matter? This isn't the space shuttle. The second would be to switch to a non-caching code path when you get close to whatever your maximum value is. So when you hit, say 990,000 views (based on your hit rate, etc.) then switch to the non-caching version for that customer.
Title: Consistency   
Name: Brian
Date: 2005-05-20 2:03:29 PM
Comment:
I had to accomplish this exact same scenario. The problem I ran into was the caching. Lets say that one of your advertisers pays you to show their ad 1 million times. How can you insure that it doesn’t go over? If you are holding the most current counters in cache, won’t each process be looking at their own cache, not to mention each server in the web farm and all it’s processes be looking at their own cache.

Another general Cache question. When I write something to cache, isn’t it only available for that particular process? So if you setup your application to have 5 worker processes, won’t that have 5 separate cache entries?
Title: web farm   
Name: parker
Date: 2005-04-24 3:19:08 AM
Comment:
How do you account for disperate sessions in a web farm scenario? Is the cache shared amoung the servers?
Title: Too Good   
Name: Zulfiqar Damani
Date: 2005-04-18 12:46:36 AM
Comment:
It presented very well, also it was interesting too.
Title: Thanks   
Name: Happel
Date: 2005-04-14 8:23:23 AM
Comment:
Thanks for sharing this article, very interesting.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-08 10:21:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search