プログラミング + アカデミック + 何か面白いこと

  1. Programming
  2. 0 view

[php5-fpm]Check point for heavy site with php5-fpm

Pocket

Overview

One day a site return 500 status with Nginx+php5-fpm+Wordpress structure.
I checked Nginx error log. I found following error.

..... [error] 846#0: *1650149 upstream timed out (110: Connection timed out) while reading response header from upstream .....

I could fix the problem with php5-fpm setting.
This article is a memo for it.

OS

Linux www3241up 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Flow

1. Check process situation with top or htop command.

php5fpm1
There are many mysql process.
Looks this is cause.

2. Change setting about php5-fpm.

$ sudo vim /etc/php5/fpm/pool.d/www.conf
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 1

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 2

Set low value.

3. Reboot php5-fpm.

$ sudo /etc/init.d/php5-fpm restart

I could solve the problem with this way.

Pocket

Programming recent post

  1. Install sbt 1.0.0 and run sample template

  2. [Machine Learning]Created docker image includ…

  3. [Node.js]How to write batch script with Node.…

  4. [Play][Scala]Develop Request Driven Batch Usi…

  5. [OpenCV][Ruby]Auto check web page design corr…

PAGE TOP