Score:0

How to understand and optimize memory used by each Apache process

gb flag

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?

John Mahowald avatar
cn flag
Which httpd MPM are you using? How is PHP run from httpd, mod_php or php-fpm or something else?
dgarg avatar
gb flag
MPM is perfork & I can see mod_php7 is one of the loaded modules
dgarg avatar
gb flag
but i can also see php-fpm as one of the active process: `root 682 0.0 0.1 368840 16140 ? Ss Jul27 0:48 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)` so i am not sure how PHP is being run
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.