0

I have a VPS box that runs a few websites for me as well as some scripts and it seems like its running out of memory. It has 1GB total memory. It looks like php-fpm exhausts the memory. Before it was simply killing other processes (like mysql) to free memory.

The error was:

php fpm has invoked oom-killer

I solved that using this solution: php-fpm invokes oom-killer

Next I tried to configure various php-fpm settings with no luck. I also increased my swap file size from 1GB to 2GB (2x my physical memory). I am running a total of 10 small websites which don't get much traffic at all so I'm confused why I am running out of memory. Besides purchasing more memory for my box, is there anything else I can do?

At this point php-fpm seems to hog up the entire 1GB of memory and most of the swap, in some cases it stops me from accessing the VPS as I can't authenticate!

Running a:

service php-fpm restart

Instantly frees up almost all the memory on the box (ie 950/990 in use goes to 200/990 in use). So what are my options? I can also post relevant configuration files if needed.

Relevant specs: OS: Centos 6.7 x86_64 RAM: 1GB Swap: 2GB php -version: PHP 5.5.35 (cli) (built: Apr 29 2016 09:07:44) php-fpm -version: PHP 5.5.35 (fpm-fcgi) (built: Apr 29 2016 09:09:09)

  • Which of the fpm process managers are you running? You will generally want to run ondemand in cases like that. dynamic or static will kill you on a box with that little memory and more then one pool, as the spare processes will eat all your precious memory. – s1lv3r Jun 6 '16 at 12:22
  • It was on dynamic, I am now trying ondemand to see if it improves the situation, looks promising. – Mo Beigi Jun 24 '16 at 12:06
3

(this should be a comment but its a bit long).

"I solved that using this solution" - unfortunately most of the opinions there are wrong.

php fpm has invoked oom-killer

This means that:

1) your system is configured to overcommit memory. Memory overcommit is useful when you have to manage badly written, long-running processes written in object oriented languages (like Java) and for vm hosts running large numbers of inactive guests. Neither seems to apply here. Setting the overcommit_memory to 2 as suggested will disable overcommit - so WTF does Chris suggest setting the overcommit_ratio to 80% (default usually about 50%) when it is disabled???

2) PHP-FPM asked for more memory and there was none left. That doesn't necessarily mean that PHP-FPM used up all the memory.

Your problem is that the config your are using does not fit in the box you are using. But describing how to configure Linux, PHP, MySQL and a webserver is somewhat off topic here.

That restarting the FPM process seems to resolve the issue suggests that the problem is PHP-FPM, but it's no smoking gun. Maybe each PHP process has an open database connection.

Since you've not posted you php-fpm config nor provided any details of your webserver, nor given any metrics about response time, this question can't be answered here.

Either spend a lot of time and effort learning how to measure your systems behavour and tune it, or buy more memory.

| improve this answer | |
  • 1
    that link is useless – stephen Apr 7 '17 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.