Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLR memory consumption problem

One of issues with CLR is it's extremely bad behavior in the lack of RAM (when some of memory of managed process gets paged out, this leads to the total freeze of the whole system, even Ctrl-Alt-Del screen can't be accessed. I assume the reason is GC which tries to build graph of reachable objects and tries to scan all memory of the process, causing massive page in/page out operations).
This makes a problem for my .NET program, coz it can consume lots of RAM when input data is huge.

I'd prefer to show a "not enough memory" message to the user, rather than completely hang his system ^_^
Is there any way to achieve this?

like image 990
fithu Avatar asked Nov 10 '10 13:11

fithu


1 Answers

With MemoryFailPoint, you can tell .NET you are going to need a certain amount of memory. The problem though is that even this system includes swap space.

I believe that it is very difficult to achieve what you want to achieve here. Say, you would use some system indicators and performance indicators to find out how much physical memory is available and based on that, perform some tasks. If after you've completed this check a different process comes in a grabs physical memory, your original calculations do not apply anymore and some of your memory is going to be pushed to swap.

I do have a suggestion. You could have a configuration setting with the maximum allowed amount of memory to be used by the application? With this, you can:

  1. Try to figure out how much resources your application consumes based on e.g. a network connection (if your application is a network server) and throttle the number of connections based on the maximum memory consumption, or

  2. You could have a second thread running that checks ever 10 seconds or minute of so the total memory consumption with GC.GetTotalMemory() and start rejecting connections (again, if your application is a network server) once you get to that maximum.

This should be a configuration setting instead of e.g. the amount of physical memory available, because you do not know what other applications are running on the machine.

like image 189
Pieter van Ginkel Avatar answered Sep 29 '22 05:09

Pieter van Ginkel