easyengine icon indicating copy to clipboard operation
easyengine copied to clipboard

PHP5-FPM consuming all CPU, 504 Gateway Time Out

Open ghost opened this issue 12 years ago • 29 comments

OS: Ubuntu 12.04 i386; 3.8.0-29-generic (current updates as of now) EasyEngine: 1.3.0

This system has 512 MB of RAM, so it is a bit small. I create a site with --wpfc and it works fine ("shell" WP site) Then I install 15 plugins I had installed on my backed up WP site (which was hosted elsewhere also with 512MB RAM but on Apache) and it's still working fine. Then I restore the main DB and PHP5-FPM goes wild:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4539 www-data 20 0 100m 14m 9760 R 15.3 2.9 0:45.78 php5-fpm 4533 www-data 20 0 102m 27m 21m R 14.9 5.6 1:05.74 php5-fpm 4535 www-data 20 0 100m 24m 19m R 14.9 5.0 1:06.02 php5-fpm 4544 www-data 20 0 100m 14m 9788 R 14.9 2.9 0:07.60 php5-fpm 4545 www-data 20 0 100m 14m 9776 R 14.9 2.9 0:07.54 php5-fpm 4538 www-data 20 0 100m 19m 14m R 14.6 3.9 0:24.43 php5-fpm ... I used default EE settings for everything. I tried adjusting some PHP5-FPM parameters and I recreated the entire site but I can't get around it.

I set "pm = ondemand" in www.conf and that seems to have helped a bit, but only initially and now I'm back to the same situation (the max. number of servers is now set to 4, so php5-fpm processes are consuming close to 100% of CPU). It seems that default values set in EE are quite high...

Any idea what could be wrong here? This WP site is basically idle and there are no other services except what's started by EE so it should be able to show pages.

Update 1: I tried various things, like "--wp" (same issue), "--w3tc" (same) and with 1GB RAM (same).

I get this error in Nginx: 2014/04/13 17:33:01 [error] 16221#0: *3 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 1.2.3.4, server: domain.com, request: "GET /wp-login.php?redirect_to=http%3A%2F%%2Fdomain.com%2Fwp-admin%2F&reauth=1 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock", host: "domain.com"

ghost avatar Apr 13 '14 10:04 ghost

On a similar note: PHP5-FPM is consuming large amount of RAM. In my case CPU is totally fine, but ram was ramped up a whopping 1.04 GB. I have 2 GB of ram on my digitalocean server

shaneholloman avatar Apr 14 '14 02:04 shaneholloman

I noticed this too, got an email this morning that my site was down. I logged in and noticed RAM usage was at 95% and mysql was stopped. I tried restarting the service using ''ee system restart' but Nginx wouldn't start, with an error about memory. So is restarted the droplet then edited 'www.conf' and changed to 'pm=ondemand' with a 10s kill time. Everything is OK now, memory usage at about 20%. There is something about 'ee 1.3' which causes PHP-FPM memory usage to balloon. I noticed this behaviour after the update.

w33zy avatar Apr 14 '14 02:04 w33zy

Same here. I have about 4 VMs with EE, updated two of them to the latest and both have been down when I wake up in the AM.

coreyallen avatar Apr 14 '14 02:04 coreyallen

@w33zy thx for the tip... would you be so kind to provide the directory location of the exact .conf file you edited? Maybe a a couple of line numbers in case it's hard for a novice to find : )

shaneholloman avatar Apr 14 '14 02:04 shaneholloman

@coreyallen thank goodness I have a ton ram on this particular install... I usually run with 1 GB

shaneholloman avatar Apr 14 '14 02:04 shaneholloman

I just looked at my www.conf and can't find a pm=ondemand setting. Is this something I need to add myself?

coreyallen avatar Apr 14 '14 02:04 coreyallen

@coreyallen /etc/php5/fpm/pool.d/www.conf

on your config it is set to 'pm = dynamic' change it to 'pm = ondemand' and uncomment 'pm.process_idle_timeout = 10s;'. Then restart ee

w33zy avatar Apr 14 '14 02:04 w33zy

@w33zy beautiful! Cheers...

shaneholloman avatar Apr 14 '14 02:04 shaneholloman

"ondemand - the processes spawn on demand (when requested, as opposed to dynamic, where pm.start_servers are started when the service is started." http://www.php.net/manual/en/install.fpm.configuration.php

when you check 'top' on your server you will notice 'php5-fpm' is only started when i webpage is requested and killed if the process idles for 10s. This goes a long way on servers with low RAM

w33zy avatar Apr 14 '14 02:04 w33zy

@w33zy I owe ya. If I ever have a kid I'll name him or her w33zy.

coreyallen avatar Apr 14 '14 02:04 coreyallen

@w33zy @coreyallen I 2nd that... thx

shaneholloman avatar Apr 14 '14 03:04 shaneholloman

https://rpm.newrelic.com/public/charts/5QmNnZMhShZ after changes!

shaneholloman avatar Apr 14 '14 03:04 shaneholloman

@coreyallen @shaneholloman yuh good! This morning it had me fretting that i needed to upgrade to a 2GB server. After i few minutes googling, i came across this and it SAVED me. Now i may be able to downgrade to a 512MB plan per website

@shaneholloman WOW! was that after switching to 'ondemand'?

w33zy avatar Apr 14 '14 03:04 w33zy

Just fine.

Idle Server = 531mb to 110mb after changes!

Thx!!

alexfares avatar Apr 14 '14 03:04 alexfares

I must have a magical Digital Ocean droplet, either that or I'm reading the numbers wrong

http://d.pr/i/GMx9/2bPiJBca

According to this php5-fpm is taking up more memory than is available.

coreyallen avatar Apr 14 '14 03:04 coreyallen

@coreyallen What about logging in to the server and running 'top' or 'free -m'?

w33zy avatar Apr 14 '14 03:04 w33zy

Well that looks a bit more sane. Still, higher than I had hoped http://d.pr/i/20ym/U4SF1UYT

coreyallen avatar Apr 14 '14 03:04 coreyallen

@coreyallen considering that the server is also running a full stack including MYSQL', that's pretty good

w33zy avatar Apr 14 '14 03:04 w33zy

Hey thanks again for the help

coreyallen avatar Apr 14 '14 03:04 coreyallen

Hi All,

Sorry for any issues you have faced, but if you compare difference between 1.2 and 1.3, we did not changed any values in www.conf. Also we did not face any issues on demo.rtcamp.com which is running on 512MB DigitalOcean VPS.

Can you please provide us details like, OS version - 64-bit vs 32-bit? Or any other useful info.

On other note if ondemand is working for all, we can make it default. But I think ondemand will also crash at some point (when server will fail to meet demand i.e. demand exceeds memory limit).

We will be using ondemand as default in shared-hosting model in future but it's not yet tested yet on any of our production server. So any feedback in this direction will be helpful.

rahul286 avatar Apr 14 '14 06:04 rahul286