Problem: Caching Block under heavy workload

Topics: Caching Application Block
Aug 17, 2007 at 1:37 AM

Recently I implemented a caching solution on top of Caching Block. It worked perfectly in all my functional tests - cache items were expired and scavenged. Then I decided to stress test this solution by generating a big workload - I was curious to see how Caching Block's expiration functionality would work. Unfortunately in all my stress tests I saw that its expiration functionality does not work at all!

Here is the pattern I saw in all my stress tests: during the test no items get removed from the cache (they are supposed to expire and get removed). As soon as the test stops the expired items get removed immediately. Please note that the test does not access the same items all the time - it rather generates new items, uses them for a limited amount of time and then abandons them. So these items must be removed by the cache's scheduler. But this never happens in my environment. If I significantly reduce the work load then the items get removed as expected during the test.

Does anyone have a clue why this happens?

As far as I can tell such a behavior can be explained if the cache's scheduler thread runs with a lower priority then all other threads. Is it the case? If it is is there a way to change this behavior without changing the caching block's code?

Aug 21, 2007 at 9:22 PM
I'm having the same problem with my load tests. If there is enough load on the application, none of the items expire until the load is gone; I then see a spate of expirations happening all at once. Strangely, this also happens when I use the caching block instrumentation to record when cache items are accessed; I get a bunch of messages once the load disappears, the access seems to be taking place all at once even though my application is using the objects in the meantime!

To see if the behavior was reproducible, I put together a test that runs 10 threads simultaneously, each adding to and removing from the cache a distinct item. Before I launched these threads, I placed an item in the cache, then slept the main thread until three times the expiration period had elapsed. Even though there are zero threads accessing the item that I wanted to see expire, it is not expired even after three times the expiration period!

Hopefully someone may have some idea as to what is going on and how to prevent it? Thanks,

- Daniel