Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have installed ngix + php5-fpm. I am happy with it but I can not optimize php5-fpm so that it works without errors. Each fixed error creates a different error.

First I had the the default settings which causet a lot of errors:

[04-Jun-2012 03:30:06] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

I increased all numbers:

pm.max_children = 15
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 5
;pm.max_requests = 500

It caused a different error:

[28-Feb-2013 07:45:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 18 idle, and 28 total children

I increased all numbers again:

pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
;pm.max_requests = 500

This caused logfile filling up with this:

[28-Feb-2013 13:21:55] NOTICE: [pool www] child 21868 exited with code 0 after 4171.293476 seconds from start
[28-Feb-2013 13:21:55] NOTICE: [pool www] child 23962 started

I uncommented:

pm.max_requests = 500

I had the same errors, but not so often - every 5 minutes:

[28-Feb-2013 13:21:55] NOTICE: [pool www] child 21868 exited with code 0 after 4171.293476 seconds from start
[28-Feb-2013 13:21:55] NOTICE: [pool www] child 23962 started

I did increase again:

pm.max_requests = 1000

Now I have this error 2-3 times per hour but it still persists.

I would increase this number again but I feel that my server (websites) work a bit slower than websites hosted on another server with settings: pm.max_children = 15,pm.start_servers = 5, pm.min_spare_servers = 3, pm.max_spare_servers = 5. (probably it's just a network issue, I don't know).

I have searched Google and this website and know how to calculate the pm.max_children (it depends of RAM). But I can not find any information how to calculate:

    pm.start_servers
    pm.min_spare_servers
pm.max_spare_servers
    pm.max_requests

Can somebody help?

uptime
 13:55:39 up 16:40,  2 users,  load average: 0.13, 0.14, 0.16


free -m
             total       used       free     shared    buffers     cached
Mem:         24101       3783      20318          0        151       3039
-/+ buffers/cache:        592      23509
Swap:         7811          0       7811

I did not change anything in nginx configuration files.

share|improve this question
    
It sounds like you have done all the correct steps to tune PHP-FPM. What problem are you having? –  Michael Hampton Feb 28 '13 at 23:18
    
The problem is the following lines in php5-fpm.log. Is it normal? [28-Feb-2013 13:21:55] NOTICE: [pool www] child 21868 exited with code 0 after 4171.293476 seconds from start [28-Feb-2013 13:21:55] NOTICE: [pool www] child 23962 started –  user1821484 Mar 1 '13 at 5:39
    
That's normal since you set pm.max_requests. –  Michael Hampton Mar 1 '13 at 5:41
    
ok, but what is the purpose of pm.max_requests? By default is not activated. –  user1821484 Mar 2 '13 at 9:44
2  
As far as I know, it will kill the child and so force the creation of a new child. This will reduce the damage done by memory leaks, as all memory of the child is freed when killed. –  Philippe Gerber Apr 3 '13 at 19:57

1 Answer 1

Switch php-fpm to dynamic mode. That way php-fpm automatically decides when to spawn new children. It is must have if you're using and type of opcode caches, because force-killed children increase fragmentation in PHP-APC

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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