I wrote a small geoip lookup linux daemon in C++, and I’m getting two different results and I’m wondering why.
This is the source code: https://github.com/homer6/geoipd
I’ve checked it with valgrind for memory leaks and there weren’t any.
I have two web servers, both running the same Ubuntu image on Amazon EC2 and both behind a load balancer that is ensuring they each get about the same amount of traffic. I installed the daemon on both servers and I’ve let them run in production for a few days now.
Everything is working as expected, but the output from “ps aux” is slightly different for the two instances.
Server 1:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
1004 28889 0.0 6.7 640288 517692 ? Ss Nov09 0:03
Server 2:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
1004 16587 0.0 6.7 574752 517688 ? Ss Nov09 0:02
My question is two-parted:
- Why is there such a big difference in the virtual memory usage?
- Why is there a difference in the resident memory usage?
Thanks in advance…
UPDATE:
I remember checking the VM size when I first launched the processes. They were both at 574752 (or slightly under 575 MB) and they both had the same value.
From these 2 extra lines in server 1’s maps:
it seems server 1 has allocated (but not initializing yet) memory for some object that server 2 has not yet. This is not necessarily bad; each kernel is most likely handling the memory properly, just different.
You can run
size geoip_server.oto make sure that the bss (uninitialized static data) is the same for the 2 daemons on each system:these numbers are made up as I do not have cmake 2.8.2 so I was unable to compile your code
Additionally, you can
cat /proc/meminfoon each system to see the specifics of how each kernel is managing its memory:This research paper from the University of Alberta on Understanding Memory is a very good read and may help explain the why a difference in VSZ for the same process running on 2 different systems can be normal.
Some references and resources:
procfs wiki page
Runtime Memory Measurement
Linux Kernel Documentation on /proc
https://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux
man proc: