WordPress – Track down a memory leak on a wordpress site

apache-2.4php-fpmWordpress

I'm running an AWS marketplace bitnami image for wordpress. The site has been running for a few months and recently started crashing. Something's leaking memory and I can't find out what it is.

I've updated php-fpm settings

pm = ondemand
pm.max_children = 20
pm.process_idle_timeout = 10s
pm.max_requests = 500

And I've drop max_memory in php.in to 64M

But I can still see the memory slowly disappearing.

bitnami@ip-172-31-7-85:/opt/bitnami/php/etc$ free -m
             total       used       free     shared    buffers     cached
Mem:          2000       1236        764         75         94        489
-/+ buffers/cache:        652       1348

The httpd and php-fpm processes just take more and more memory till the site falls over.

bitnami@ip-172-31-7-85:/opt/bitnami/apache2/logs$ ps aux --sort -rss
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mysql     1478  0.6 11.0 1392736 227120 ?      Sl   19:35   0:24 /opt/bitnami/mysql/bin/mysqld.bin --defaults-file=/opt/bitnami/mysql/my.cnf --basedir=/opt/bitnami/mysql --datadir=/opt/bitnami/m
daemon    3841  1.1  3.0 1305952 62988 ?       Sl   20:36   0:01 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
daemon    4045  4.3  2.5 286040 51928 ?        S    20:36   0:06 php-fpm: pool wordpress                                                                                                          
daemon    3843  0.7  2.4 1305496 50564 ?       Sl   20:36   0:01 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
daemon    4047  3.5  2.4 286012 50356 ?        S    20:36   0:05 php-fpm: pool wordpress                                                                                                          
daemon    3842  0.8  2.4 1305892 50020 ?       Sl   20:36   0:01 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
daemon    4048  0.6  2.3 1297712 48532 ?       Sl   20:36   0:01 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
daemon    4118  3.0  2.1 285992 44916 ?        R    20:36   0:04 php-fpm: pool wordpress                                                                                                          
daemon    4116  3.9  2.1 286000 44856 ?        S    20:36   0:06 php-fpm: pool wordpress                                                                                                          
daemon    4115  1.4  1.6 273832 34420 ?        S    20:36   0:02 php-fpm: pool wordpress                                                                                                          
root      3831  0.0  1.1 206004 23300 ?        Ss   20:36   0:00 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
root      3793  0.0  0.3 267808  7836 ?        Rs   20:35   0:00 php-fpm: master process (/opt/bitnami/php/etc/php-fpm.conf)

The sites under very low load. But it's only taking 10 mins before it crashes.

I'm getting the following in my error_log

[Thu Mar 09 18:43:49.420787 2017] [pagespeed:warn] [pid 1549:tid 140430532409088] [mod_pagespeed 1.9.32.14-0 @1549] Fetch timed out: http://ourdomaincom/wp-content/uploads/2015/01/ourdomain_page_3.jpg-200x200.jpg (connecting to:172.31.7.85) (1) waiting for 50 ms
[Thu Mar 09 18:43:49.583085 2017] [pagespeed:warn] [pid 2201:tid 140430112970496] [mod_pagespeed 1.9.32.14-0 @2201] Fetch timed out: http://ourdomain.com/wp-content/plugins/LayerSlider/static/js/layerslider.transitions.js?ver=5.6.9 (connecting to:172.31.7.85) (1) waiting for 50 ms
[Thu Mar 09 18:43:49.584180 2017] [pagespeed:warn] [pid 1548:tid 140430381405952] [mod_pagespeed 1.9.32.14-0 @1548] Fetch timed out: http://ourdomain.com/wp-content/themes/thefox/js/custom_woo_js.js?ver=4.6.1 (connecting to:172.31.7.85) (1) waiting for 50 ms

How can I fix this or track down the memory leak?

Best Answer

Turns out the site had been hacked.

I migrated it into the hands of the fine folks at WPEngine. They've been amazing, identifying the problem, and sorting it quickly.

It's not been a good introduction to wordpress. Kind of hope I never have to look after another wp installation :(

Related Topic