Re: Strategy for caches & GC
- From: Barry Kelly <barry.j.kelly@xxxxxxxxx>
- Date: Mon, 21 Apr 2008 11:35:34 +0100
devdude wrote:
I am currently using the Enterprise Library Caching Block on a server
that receives incoming calls and stores/retrieves random information.
I noticed while load testing, the system is slow to respond (a call
can take several seconds) during scavenging of old items when the
threshold is met. It is reclaiming approx 4gb of data during each
scavenge on approximately 14gb of cache. I realize this is a lot of
information but am looking for strategies to implement a performant
cache in .Net. I'm not particularly married to entlib so anything is
an option.
It sounds like you need a more aggressive cache expiration policy. As
Rico Mariani [Google] likes to say, a poorly implemented expiration
policy is just a memory leak by another name. What you say makes me
think that the cache is getting a too-low hit rate, so it needs throw
away most of it too often. Perhaps it shouldn't be caching much of this
stuff at all in the first place?
When dealing with large amounts of data, I find GC is often not the best
way to go. I end up writing manual allocators for byte arrays. This
makes most sense when the data you're caching is in fact a byte array,
or other value-typed array, of course. However, I still allocate those
byte arrays from the .NET GC. It's just that they're all over the large
block limit (80K or so), and I carefully recycle them through a pool.
One thought I had was to perhaps rewrite the cache (or a new one from
scratch) in C++/CLI to handle all the memory storage/reclamation in
native code but am concerned with marshalling data back and forth
between native/managed code. That said, the GC multisecond swings are
worse then knowing that a call to the cache will take, for example,
5ms, instead of 1ms.
BTW, you can still do manual memory allocation in C#, using the Marshal
class or by writing the PInvoke signatures yourself. However, I'd take a
closer look at your expiration policy before I'd go off and try and
reimplement a cache.
-- Barry
--
http://barrkel.blogspot.com/
.
- Follow-Ups:
- Re: Strategy for caches & GC
- From: devdude
- Re: Strategy for caches & GC
- References:
- Strategy for caches & GC
- From: devdude
- Strategy for caches & GC
- Prev by Date: RE: .NET Runtime 2.0 Error Reporting , Event ID:5000 Application Crash
- Next by Date: Re: Strategy for caches & GC
- Previous by thread: Strategy for caches & GC
- Next by thread: Re: Strategy for caches & GC
- Index(es):
Relevant Pages
|
Loading