Guides
Production
Performance Tuning

Performance Tuning

Toutes les configurations PHP, MySQL, PostgreSQL et Apache sont pilotables depuis le fichier .env. Modifier les variables + docker compose up -d suffit pour appliquer les changements.


Architecture

CSWeb utilise un mecanisme de templates envsubst :

  1. Les fichiers docker/php/php.ini et docker/apache/*.conf contiennent des variables ${VAR}
  2. Au demarrage du container, docker-entrypoint.sh execute envsubst pour generer les fichiers finaux
  3. MySQL et PostgreSQL recoivent leurs parametres via command: dans docker-compose.yml

Variables par composant

PHP

VariableDefaultDescription
PHP_MEMORY_LIMIT512MMemoire max par processus PHP
PHP_MAX_EXECUTION_TIME300Temps max d'execution (secondes)
PHP_MAX_INPUT_TIME300Temps max de parsing input
PHP_UPLOAD_MAX_FILESIZE100MTaille max d'un fichier uploade
PHP_POST_MAX_SIZE100MTaille max d'une requete POST
PHP_SESSION_GC_MAXLIFETIME7200Duree de session (secondes)
PHP_OPCACHE_MEMORY128Memoire OPcache (MB)
PHP_OPCACHE_MAX_FILES10000Nombre max de fichiers en cache

Exemple .env :

PHP_MEMORY_LIMIT=1G
PHP_MAX_EXECUTION_TIME=600
PHP_OPCACHE_MEMORY=256

Verifier apres deploiement :

docker exec csweb-app php -i | grep memory_limit
docker exec csweb-app php -i | grep max_execution_time

Profils de dimensionnement

Profil Dev — 1 a 5 utilisateurs, laptop

# PHP
PHP_MEMORY_LIMIT=256M
PHP_MAX_EXECUTION_TIME=120
PHP_OPCACHE_MEMORY=64
PHP_OPCACHE_MAX_FILES=4000

# MySQL
MYSQL_MAX_CONNECTIONS=50
MYSQL_INNODB_BUFFER_POOL_SIZE=128M

# PostgreSQL
PG_MAX_CONNECTIONS=50
PG_SHARED_BUFFERS=128MB
PG_EFFECTIVE_CACHE_SIZE=512MB

# Apache
APACHE_MAX_REQUEST_WORKERS=25
APACHE_SERVER_LIMIT=25

RAM recommandee : 4 GB


Formules de dimensionnement

Memoire totale requise

RAM_TOTALE >= (APACHE_MAX_REQUEST_WORKERS x PHP_MEMORY_LIMIT moyen)
           + MYSQL_INNODB_BUFFER_POOL_SIZE
           + PG_SHARED_BUFFERS
           + 1 GB (OS + overhead)

En pratique, les processus PHP utilisent ~50-100 MB en moyenne (rarement le max).

Exemple pour 150 workers :

150 x 100MB + 512MB + 512MB + 1GB = ~17 GB (estimation realiste)

Connexions base de donnees

MYSQL_MAX_CONNECTIONS >= APACHE_MAX_REQUEST_WORKERS + 20 (marge admin/cron)
PG_MAX_CONNECTIONS    >= APACHE_MAX_REQUEST_WORKERS + 20

Apache ServerLimit

APACHE_SERVER_LIMIT >= APACHE_MAX_REQUEST_WORKERS (obligatoire)

Commande de verification

La commande csweb:check-config affiche toute la configuration et detecte les incoherences :

# Afficher la configuration complete
docker exec csweb-app php bin/console csweb:check-config
 
# Avec test des connexions MySQL et PostgreSQL
docker exec csweb-app php bin/console csweb:check-config --test-connections
 
# Sortie JSON (pour monitoring automatise)
docker exec csweb-app php bin/console csweb:check-config --json

Recommandations automatiques :

  • Apache MaxRequestWorkers > MySQL max_connections
  • ServerLimit < MaxRequestWorkers
  • post_max_size < upload_max_filesize
  • memory_limit trop bas

Workflow de modification

# 1. Modifier les variables dans .env
nano .env
 
# 2. Recreer les containers
docker compose up -d
 
# 3. Verifier la configuration
docker exec csweb-app php bin/console csweb:check-config
 
# 4. Verifier PHP specifiquement
docker exec csweb-app php -i | grep memory_limit

Les changements sont appliques au redemarrage des containers (docker compose up -d). Pas besoin de rebuild (--build).


Voir aussi