Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strategy for memory consumption management

We are designing an enterprise application which caches a lot of data from back end. The users are allowed to open arbitrary number of app windows, and each loads its own data and caches it. To somehow manage memory consumption and prevent overall OS performance decrease, we decided to write a cache manager that will automatically monitor app's memory footprint and remove data from cache when needed.

So the problem is we have difficulties identifying whether it is time to free up memory. Currently we use a very simple approach - we just start throwing away stuff from cache when app's memory usage exceeds 80% of physical memory.

Are there any (alternative?) established practices for dealing with such kind of problem?

like image 789
george.zakaryan Avatar asked Oct 19 '22 08:10

george.zakaryan


1 Answers

This is basically OK. There is no really good strategy. If there are multiple competing applications this can lead to cache competitions and false evictions.

If you pick the threshold too low you waste cache space. If it's too high nothing else might fit into memory including the file cache, DLLs, ...

What do you mean by "available physical memory"? Do you mean installed memory or memory that's free? How can an app use 80% of free memory? I'm unclear on the definition that you are using.

SQL Server uses memory until the OS signals that it's low on memory (I believe that happens when 95% of "something" is being used).

You certainly do not want to use the GC to free memory. It will routinely kill your entire cache.

Maybe you can move the cache contents to disk entirely? Or, you could share the cache between .NET processes by having a hidden cache server process that can be queries by app processes.


I want to stress that if your app consumes 99% of installed RAM (as an example) performance will be very bad because the file cache is almost empty. This means that even DLLs and .NET NGEN'ed code will be paged out and in frequently.

Maybe a better strategy is to assume, that 1GB will be needed to appropriately cache the OS and app files. So you can consume memory until there are only 10% free of the installed RAM minus 1 GB.

like image 51
usr Avatar answered Oct 21 '22 04:10

usr