Memory profiling tools

I have a server program that uses a lot of unbounded Containers. Are there any good tools for inspecting heap memory usage during runtime, or do I need to instrument things myself by calling Length on all of the containers periodically?

There’s “GNAT debug pool” that gathers usage information about the objects that use its memory pool.


You may find these informative:

3 Likes

You need a health monitoring tool. Memory debugging tools usually do postmortem checks.

The first step would be replacing unbounded containers with arena allocating. A server does not need fully dynamic memory management. Typically you allocate memory per session and for the session only so long the session exist. Then you release all session’s memory. Beware controlled types which require finalization. You would need a list of such object to go through and call Finalize before dropping the arena.

Furthermore, it is a good idea to limit the amount of memory per session. Not only the objects, but also all communication buffers, e.g. a HTTP server has input and output buffers and the response buffer. Chunked transfers can be accumulated in separate arena buffer. In the end you would know the exact upper limit a connection may consume.

For memory monitoring in general, see: GetProcessMemoryInfo under Windows and mallinfo under Linux. Note that memory is allocated in chunks.

You could also use a non-standard pool with more health statistics available. Note that debug pools have a different goal and heavy overheads. Also it is usually difficult to substitute the pool in a container. Arena pool and custom data structure is usually a better choice.

2 Likes