I am aware of the method to get the average memory used by each apache2 process using ps. I have observed it and it is coming out to be around 18MB (Although it seemed to have spiked from last 2 days from 18MB avg to 25MB).
Our server is serving an API which accepts some data and stores it in a mysql db. The api is written in PHP. I have used PHP mem_get_usage and mem_get_peak_usage functions to understand the memory usage but they are nowhere close to 18MB.. (mostly shows below 1MB)
So I dont understand what is consuming this huge memory per apache process. This has become a bottleneck as our total RAM is limited and with this consumption we are forced to limit maxrequestworkers which brings lag in serving the clients when there is high traffic.
Typical output from ps:
www-data 30024 0.0 0.3 494384 26124 ? S 04:27 0:03 /usr/sbin/apache2 -k start
www-data 30077 0.0 0.3 494368 26136 ? S 04:28 0:04 /usr/sbin/apache2 -k start
www-data 30078 0.4 0.3 494360 25960 ? S 04:28 0:21 /usr/sbin/apache2 -k start
www-data 30080 0.1 0.3 494376 26140 ? S 04:28 0:05 /usr/sbin/apache2 -k start
www-data 30115 0.2 0.3 494448 26180 ? S 04:28 0:11 /usr/sbin/apache2 -k start
www-data 30124 0.1 0.3 494376 26212 ? S 04:28 0:07 /usr/sbin/apache2 -k start
www-data 30132 0.0 0.3 494376 26108 ? S 04:28 0:03 /usr/sbin/apache2 -k start
www-data 30135 0.0 0.3 494376 26164 ? S 04:28 0:04 /usr/sbin/apache2 -k start
www-data 30219 0.0 0.3 494352 26108 ? S 04:29 0:03 /usr/sbin/apache2 -k start
Any suggestions on how to monitor the memory usage per apache2 process and how to reduce/optimize it?