PHP-FPM and nginx tweaks - My server is OOMing (so it seems)
So, from some days ago my server started giving error 504 Gateway timeout. According to the Linode support my server started OOMing with php-fpm processes. There are a few interesting things that I would like to question:
Despite the fact that the process killer is being engaged when this type of problem happens, if I log in my server with regular SSH and check it with htop, it doesn't look like I'm out of memory at all.
This problem is happening at odd moments. It happens when the traffic is extremely lower than when it works just fine which makes me think that maybe I'm getting zombie processes and they are piling up and filling up the memory. Does anyone knows if that can happen and how can I prevent it?
My PHP-FPM version is…
PHP 5.3.5-1ubuntu7.2 (fpm-fcgi) (built: May 2 2011 23:26:15)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
And my nginx version is…
nginx version: nginx/1.0.1
Here is an excerpt of my php-fpm configuration:
The "pm.max_requests = 500" is a new one and I didn't have any problems so far. We are waiting
Thanks!
9 Replies
Depending on your linode size I'd say pm.maxchildren = 60 is high pm.startservers = 20 is high … pm.minspareservers = 5 is high… pm.max_requests = 500 is probably low
Also consider using a unix socket instead of binding to a port, they're a bit faster.
@obs:
What size is your linode and what software are you running anything memory intensive (lots of wordpres/drupal plugins, image processing etc)?
Depending on your linode size I'd say pm.maxchildren = 60 is high pm.startservers = 20 is high … pm.minspareservers = 5 is high… pm.max_requests = 500 is probably low
Also consider using a unix socket instead of binding to a port, they're a bit faster.
I'm running just one web app that evolves a lot of image resizing. It's a kind of heavy application and it runs on a 1024 Linode.
I'll try the socket instead of the port and reduce pm values. Any tips on what should I use instead?
And should I use pm.max_requests = 0? Or increase the number is a better approach?
Thanks guys!
pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 2
This will allow 6 processes to use 75% of your system resources assuming each process uses at most 128mb ram. This is pretty conservative I doubt your image processing will use that much ram but better safe than sorry.
Keep an eye on it and increase the pm.max_children by 1 until you're happy you're using the right amount of ram.
pm.max_requests is used to kill a process after it's run X amount of requests, good for dealing with memory leaks you can set it to 0 and see if your system stays stable if it doesn't then set it to say 5000 and keep an eye on it dropping it if you still have problems.
I tried this config but after an hour or so I started getting the 504 error again. This time I think the VM wasn't OOMing. I was monitoring it closely.
I've increased pm.max_children = 10 and let's see what happens. Any other tips?
> Jul 15 14:51:28.178668 [NOTICE] Terminating …
Jul 15 14:51:28.191899 [NOTICE] exiting, bye-bye!
Jul 15 14:51:28.269103 [NOTICE] configuration file /etc/php5/fpm/main.conf test is successful
Jul 15 14:51:28.327797 [NOTICE] fpm is running, pid 2112
Jul 15 14:51:28.331697 [NOTICE] ready to handle connections
Jul 15 14:51:32.333643 [WARNING] [pool www] seems busy (you may need to increase startservers, or min/maxspare_servers), spawning 8 children, there are 0 idle, and 7 total children
Jul 15 14:51:33.334597 [WARNING] [pool www] seems busy (you may need to increase startservers, or min/maxspare_servers), spawning 16 children, there are 0 idle, and 9 total children
Jul 15 14:51:34.334975 [WARNING] [pool www] seems busy (you may need to increase startservers, or min/maxspare_servers), spawning 32 children, there are 0 idle, and 11 total children
Jul 15 14:51:46.343101 [WARNING] [pool www] server reached max_children setting (20), consider raising it
Thanks for the help guys
I reallly need some help here! Nothing is working… I've upgraded my linode to a 2048, increased the number of processes and I keep getting errors…
My traffic has grown A LOT these late days and I really need some help here. I'm kind of freaking out. Anything would help. Thanks!