Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query from database or from memory? Which is faster?

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!

like image 603
Guilherme de Jesus Santos Avatar asked Oct 19 '25 09:10

Guilherme de Jesus Santos


2 Answers

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.

like image 119
Henk Holterman Avatar answered Oct 21 '25 23:10

Henk Holterman


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

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

like image 29
Luca C. Avatar answered Oct 21 '25 21:10

Luca C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!