Skip to content

Instantly share code, notes, and snippets.

@asciitohex
Forked from holmberd/php-pools.md
Created March 22, 2020 08:54
Show Gist options
  • Save asciitohex/f2fd4882488772e896ee973c5f84d944 to your computer and use it in GitHub Desktop.
Save asciitohex/f2fd4882488772e896ee973c5f84d944 to your computer and use it in GitHub Desktop.

Revisions

  1. @holmberd holmberd revised this gist Jul 22, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -46,11 +46,16 @@ pm.max_request = 1000
    ; following directives:
    ; pm.max_children - the maximum number of children that can
    ; be alive at the same time.
    ;
    ; pm.start_servers - the number of children created on startup.
    ; this value must not be less than min_spare_servers
    ; and not greater than max_spare_servers.
    ;
    ; pm.min_spare_servers - the minimum number of children in 'idle'
    ; state (waiting to process). If the number
    ; of 'idle' processes is less than this
    ; number then some children will be created.
    ;
    ; pm.max_spare_servers - the maximum number of children in 'idle'
    ; state (waiting to process). If the number
    ; of 'idle' processes is greater than this
  2. @holmberd holmberd revised this gist Feb 28, 2018. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    # Adjusting child processes for PHP-FPM (Nginx)

    When setting these options consider the following:

    - How long is your average request?
    - What is the maximum number of simultaneous visitors the site(s) get?
    - How much memory on average does each child process consume?

    ## Determine if the max_children limit has been reached.
    - `sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log`

    @@ -32,4 +38,24 @@ pm.max_spare_servers = 3
    pm.max_request = 1000
    ```

    ```
    ; Choose how the process manager will control the number of child processes.
    ; Possible Values:
    ; static - a fixed number (pm.max_children) of child processes;
    ; dynamic - the number of child processes are set dynamically based on the
    ; following directives:
    ; pm.max_children - the maximum number of children that can
    ; be alive at the same time.
    ; pm.start_servers - the number of children created on startup.
    ; pm.min_spare_servers - the minimum number of children in 'idle'
    ; state (waiting to process). If the number
    ; of 'idle' processes is less than this
    ; number then some children will be created.
    ; pm.max_spare_servers - the maximum number of children in 'idle'
    ; state (waiting to process). If the number
    ; of 'idle' processes is greater than this
    ; number then some children will be killed.
    ; Note: This value is mandatory.
    ```


  3. @holmberd holmberd revised this gist Feb 28, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -11,15 +11,15 @@

    ## Calculate max_children
    ### Based on RAM
    `pm.max_children = Total RAM dedicated to the web server / Max child process size`
    - `pm.max_children = Total RAM dedicated to the web server / Max child process size`

    - System RAM: 2GB
    - Average Pool size: 85Mb
    - `pm.max_children = 1500MB / 85MB = 17`

    #### Based on average script execution time
    max_children = (average PHP script execution time) * (PHP requests per second)
    visitors = max_children * (seconds between page views) / (avg. execution time)
    - `max_children = (average PHP script execution time) * (PHP requests per second)`
    - `visitors = max_children * (seconds between page views) / (avg. execution time)`

    ## Configure
    `sudo vim /etc/php/7.0/fpm/pool.d/www.conf`
  4. @holmberd holmberd revised this gist Feb 28, 2018. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion php-pools.md
    Original file line number Diff line number Diff line change
    @@ -9,12 +9,18 @@
    - Average memory: `ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'`
    - All fpm processes memory: `ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm`

    ## Calculate (pm.max_children = Total RAM dedicated to the web server / Max child process size)
    ## Calculate max_children
    ### Based on RAM
    `pm.max_children = Total RAM dedicated to the web server / Max child process size`

    - System RAM: 2GB
    - Average Pool size: 85Mb
    - `pm.max_children = 1500MB / 85MB = 17`

    #### Based on average script execution time
    max_children = (average PHP script execution time) * (PHP requests per second)
    visitors = max_children * (seconds between page views) / (avg. execution time)

    ## Configure
    `sudo vim /etc/php/7.0/fpm/pool.d/www.conf`

  5. @holmberd holmberd revised this gist Feb 28, 2018. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    # Adjusting child processes for PHP-FPM (Nginx)
    - `ps -ylC php-fpm7.0 --sort:rss`
    - `ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'`

    ## Determine if the max_children limit has been reached.
    - `sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log`

    ## Determine system RAM and average pool size memory.
    - `free -h`
    - `ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm`
    - All fpm processes: `ps -ylC php-fpm7.0 --sort:rss`
    - Average memory: `ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'`
    - All fpm processes memory: `ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm`

    ## Calculate (pm.max_children = Total RAM dedicated to the web server / Max child process size)

  6. @holmberd holmberd revised this gist Feb 28, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # Adjusting child processes for PHP-FPM (Nginx)
    - `ps -ylC php-fpm7.0 --sort:rss`
    - `ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'`

    ## Determine system RAM and average pool size memory.
    - `free -h`
  7. @holmberd holmberd created this gist Jan 4, 2018.
    24 changes: 24 additions & 0 deletions php-pools.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # Adjusting child processes for PHP-FPM (Nginx)

    ## Determine system RAM and average pool size memory.
    - `free -h`
    - `ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm`

    ## Calculate (pm.max_children = Total RAM dedicated to the web server / Max child process size)

    - System RAM: 2GB
    - Average Pool size: 85Mb
    - `pm.max_children = 1500MB / 85MB = 17`

    ## Configure
    `sudo vim /etc/php/7.0/fpm/pool.d/www.conf`

    ```
    pm.max_children = 17
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3
    pm.max_request = 1000
    ```