0

I have created a server with C++/Boost::asio and I did notice that the amount of memory being used (committed, private, working set) by the process increases when it runs for a long time (several days or weeks) AND the memory available in the system is 'low' (most of it being consumed by another process, SQL Server). The problem doesn't arise when there is a little bit more memory available in the system.

The system has Windows Server 2008 R2 and SQL Server 2008 R2. My server is constantly processing lots of messages of different sizes (a few bytes and hundreds of bytes long). I think is not a memory leak because at some point, when the memory used by the program gets very high it suddenly releases nearly all of it without apparently any reason and everything continues as usual. I have also checked the server with a couple of memory leaks detectors (Visual Leak Detector and Microsoft Application Verifier).

I would like to know about the origin of this behaviour. Not really sure why. I have several theories involving memory fragmentation but the memory used is released as soon as one request finishes and every allocation uses boost::shared_ptr's.

EDIT: Well, it turned out that I am a moron. I have just discovered that one of my clients (some of them are written in Java) were silently throwing an exception (nothing to do with the connection itself, it were occurring in another part of the Java program). Then, the session opened in my server was not being able of writing the queued data to the client. So the connection is in the state ESTABLISHED but no write errors happen because it seems that the write handlers are never executed. So memory use starts growing with many handler awaiting for... what? I do not get it. They will be there forever?

I solved this by adding a deadline timer for writings on the server side. I close the connection if a write takes too long so the client has to reconnect.

Is this a good solution or there are other situations where these kind of problems could happen.

Thank and sorry if someone get confused with my question.

ChrisPeterson
  • 419
  • 4
  • 15
  • Maybe the memory is low _because_ your application leaks memory or requests never finish? It is impossible from just your post. Do you have a handy testcase? – Sebastian Mach Feb 11 '14 at 13:15
  • I had something similar with a recording tool that recorded udp packets using boost::asio. Top told me that the tool slowly but surely used all of the 100G memory available. But when free memory got below something like 300M, huge chunks of ~1G got released and were free to use. I assumed it had something to do with the OS not asking for new memory or something. And as it did not hinder performance at all, i just ignored it. edit: It was not due to hard disk buffering or something, i explicitly flushed and synced and the memory would remein in use even if the recorder took a break. – DeVadder Feb 12 '14 at 07:46

0 Answers0