Skip to content

Instantly share code, notes, and snippets.

@bikalbasnet
Created March 27, 2022 09:39
Show Gist options
  • Select an option

  • Save bikalbasnet/7715d396dcfade63b00c8d6428c0bf3f to your computer and use it in GitHub Desktop.

Select an option

Save bikalbasnet/7715d396dcfade63b00c8d6428c0bf3f to your computer and use it in GitHub Desktop.
Determining correct number of child process for php-fpm on nginx
1. Find if you do not have enough processes available for php-fpm
Search for php-fpm.log to find following kinds of errors suggesting you need to increase `pm.max_children` value
```
WARNING: [pool www] server reached pm.max_children setting (35), consider raising it
```
2. Find average memory usage per php process
List php fpm process by RSS. RSS (Resident Set Size) is the portion of memory occupied by a process that is held in RAM
```
ps -ylC php-fpm --sort:rss
```
Or simplu get average of one php-fpm process
```
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"Mb") }'
```
3. Calculate value for max_children
```
pm.max_children = Total Available RAM for running PHP Processes / Average memory per process
```
If only 14 GB can be used out of 16 GB RAM EC2 Container
```
pm.max_children = 14 GB / 60 MB
= 233
```
4. Change the value in `www.conf` file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment