Skip to content

Instantly share code, notes, and snippets.

@renoirb
Created February 27, 2014 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renoirb/9242830 to your computer and use it in GitHub Desktop.
Save renoirb/9242830 to your computer and use it in GitHub Desktop.
Making systematic variable configuration based on server provisioning.
{%- set ram_int = salt['grains.get']('mem_total', '1024') // 1024 -%}
{%- set max_clients = ram_int * 150 -%}
{%- if ram_int == 1 -%}
{%- set max_per_child = 1000 -%}
{%- elif ram_int == 2 -%}
{%- set max_per_child = 10000 -%}
{%- else -%}
{%- set max_per_child = 0 -%}
{%- endif -%}
# Edited by Salt Stack, generated with calculations
# based on the curernt system available resources
#
# see:
# - http://linuxstuffs.wordpress.com/apache-optimization/
# - https://servercheck.in/blog/3-small-tweaks-make-apache-fly
# - http://coolpandaca.wordpress.com/2012/03/20/apache-mpm-worker-prefork-mod_php-mod_fcgid-mod_fastcgi-php-fpm-and-nginx/
#
# Useful commands:
#
# The following commands are useful to calculate process usage and average
# memory usage on a given moment.
#
# - ps aux | grep 'apache2' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
# - ps aux | grep 'apache2' | awk '{print $6/1024 " MB";}'
#
# Current system memory: {{ salt['grains.get']('mem_total', 'ERROR') }}
#
MinSpareServers 15
MaxSpareServers 20
ServerLimit {{ max_clients }}
MaxClients {{ max_clients }}
MaxRequestsPerChild {{ max_per_child }}
Timeout 150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment