Question

I am trying to improve the performance of a Windows Service, developed in C# and .NET 2.0, that processes a great amount of files. I want to process more files per second.

In its process, for each file, the service does a database query to retrieve some parameters of the system.

Those parameters change annually, and I am thinking that I would gain some performance, if a loaded those parameters as a singleton and refreshed this singleton periodically. Instead of make a database query for each file being processed, I would get the parameters from memory.

To complete the scenario : I am using Windows Server 2008 R2 64 Bits, SQL Server 2008 is the database, C# and .NET 2.0 as already mentioned.

I am right in my approach? What would you do?

Thanks!

Was it helpful?

Solution

Those parameters change anually

Yes, do cache them in memory. Especially if they are large or complex.

You should take care to invalidate them at the right time once a year, depending how accurate that has to be.

Simply caching them for an hour or even for a few minutes might be a good compromise.

OTHER TIPS

Crossing a network or going to disk is always orders of magnitude slower than in memory access.

Databases can cache data in memory so if you can achieve that and you're not crossing a network, the database might be faster since their data access patterns/indexes etc... may be faster than you're code. But, that's best case - if you need it faster, in memory caches help.

But, be aware that in memory caches can add complexity and bugs. You have to determine the lifetime of the cached data, how to refresh and the more complex it is, the more wierd edge case state bugs you will have. Even though they change annually, you have to handle that cusp.

RAM memory data access is definitely faster that any other data access, except than cpu memories like registries and CPU cache

Chaching would be faster even if you change it every minute, so yes, caching that query is very faster

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top