2

I'm running PHP-FPM on my Debian servers. My question is about the memory usage. I can only set the memory_limit inside PHP, and that shouldn't be too low for some requests. I also can only set the number of processes in PHP-FPM and that, also, should not be too low since I'm running a lot of php requests.

In most cases, processes will only use around 2-20mb. The process limit is 512, so that's roughly 5-10GB of RAM. But since some php scripts can use a lot more memory, the maximum allowed memory is around 1TB (512 processes * 2048mb). And if something goes wrong, the Debian OOM Killer will just randomly kill processes.

Is there any way to limit the total memory usage for php-fpm? Like a hard limit where php-fpm won't spawn more processes because it's out of total RAM.

5
  • Do you know which urls will lead to larger memory usage ? Commented Feb 27, 2015 at 7:18
  • I know sites where it's more likely to happen, yes. Commented Feb 27, 2015 at 7:19
  • Use different php-fpm pools for the larger memory sites. Commented Feb 27, 2015 at 7:20
  • I'll try if that works for me Commented Feb 27, 2015 at 7:22
  • Don't give it 512 processes, then. If you want to have a 2048 limit per process, then only have as much as the machine can handle. aka. 4 processes if the machine has 10gb ram. Using alternate pools sounds appropriate. Using ulimit over the parent process will not be graceful. Commented Feb 27, 2015 at 7:22

1 Answer 1

0

Few days ago I had similar problem, when couple of php5-fpm masters spawned too much processes. OOM Killer helped a lot by killing nginx.

As solution I found cgroup mechanism with memory subsystem. It allows to put all FPM processes in 1 group which is limited to e.g. 60% of system RAM.

Great documentation: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/ch-Using_Control_Groups.html

1
  • this looks like something :) Commented Feb 27, 2015 at 13:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.