Aller au contenu principal

Chapitre 12.2 - Performance Tuning

Objectifs d'Apprentissage​

À la fin de ce chapitre, vous serez capable de:

  • Identifier les goulots d'étranglement
  • Optimiser les performances CPU
  • Optimiser la mémoire
  • Optimiser les I/O disque
  • Configurer les paramètres kernel
  • Monitorer les performances

Identification des Problèmes​

Outils de Diagnostic​

# CPU
top, htop, mpstat
cat /proc/stat

# Mémoire
free -h
vmstat
cat /proc/meminfo

# Disque
iostat -x
iotop
df -h

# Réseau
iftop, nethogs
ss -i

Métriques Clés​

# Load average
uptime
# Interprétation: < nombre CPUs

# CPU idle
mpstat 1
# Objectif: > 20% idle

# Mémoire disponible
free -h
# Objectif: > 10% libre

# I/O wait
iostat -x 1
# Objectif: < 5%

Optimisation CPU​

Priorités Processus​

# Ajuster nice values
nice -n 10 commande # Priorité basse
nice -n -10 commande # Priorité élevée (root)

# Renice processus existant
renice 10 PID
renice 10 -u user1

CPU Affinity​

# Assigner processus à CPU spécifique
taskset -c 0,1 commande

# Processus existant
taskset -cp 0,1 PID

Limites CPU​

# cgroups v2
systemd-run --slice=my-slice --property=CPUQuota=50% commande

# cpuset
cset set -c 0-3 -s my-set
cset proc -m -p PID -s my-set

Optimisation Mémoire​

Swap​

# Voir swap
free -h
swapon --show

# Ajuster swappiness
# /etc/sysctl.conf
vm.swappiness=10 # 0-100, plus bas = moins swap

# Appliquer
sudo sysctl -p

Cache et Buffer​

# Vider cache (si nécessaire)
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches

# Vérifier utilisation
free -h

Limites Mémoire​

# ulimit
ulimit -v 1000000 # 1GB en KB

# cgroups
systemd-run --slice=my-slice --property=MemoryLimit=1G commande

Optimisation I/O​

Systèmes de Fichiers​

# Choisir FS approprié
# - ext4: Général
# - xfs: Gros fichiers
# - btrfs: Snapshots

# Options montage
# /etc/fstab
/dev/sda1 /data xfs defaults,noatime 0 2
# noatime: Pas de mise à jour atime (performance)

I/O Scheduler​

# Voir scheduler actuel
cat /sys/block/sda/queue/scheduler

# Changer scheduler
echo deadline > /sys/block/sda/queue/scheduler

# Permanent: kernel parameter
# elevator=deadline

RAID et LVM​

# RAID pour performance
# - RAID 0: Performance (pas de redondance)
# - RAID 10: Performance + redondance

# LVM pour flexibilité
# - Extension volumes
# - Snapshots

Paramètres Kernel​

sysctl​

# Voir paramètres
sysctl -a

# Modifier temporairement
sudo sysctl vm.swappiness=10

# Permanent: /etc/sysctl.conf
vm.swappiness=10
net.core.rmem_max=16777216
net.core.wmem_max=16777216

# Appliquer
sudo sysctl -p

Paramètres Réseau​

# /etc/sysctl.conf
# Optimisation TCP
net.core.somaxconn=1024
net.ipv4.tcp_max_syn_backlog=2048
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=300

Paramètres Mémoire​

# /etc/sysctl.conf
vm.swappiness=10
vm.dirty_ratio=15
vm.dirty_background_ratio=5

Optimisation Services​

Services Inutiles​

# Voir services actifs
systemctl list-units --type=service --state=running

# Désactiver services inutiles
sudo systemctl disable service-name
sudo systemctl stop service-name

Limites Ressources​

# Unit file systemd
[Service]
MemoryLimit=512M
CPUQuota=50%
IOWeight=100

Monitoring Performance​

Scripts de Monitoring​

#!/bin/bash
# Monitoring performance

echo "=== CPU ==="
top -bn1 | grep "Cpu(s)"
mpstat 1 1

echo "=== Mémoire ==="
free -h
vmstat -s

echo "=== Disque ==="
iostat -x 1 1
df -h

echo "=== Réseau ==="
ss -i

Alertes Performance​

#!/bin/bash
# Alertes performance

# CPU
CPU_IDLE=$(mpstat 1 1 | tail -1 | awk '{print $NF}')
if (( $(echo "$CPU_IDLE < 20" | bc -l) )); then
echo "ALERTE: CPU idle à ${CPU_IDLE}%"
fi

# Mémoire
MEM_FREE=$(free | grep Mem | awk '{printf "%.0f", $4/$2 * 100}')
if [ "$MEM_FREE" -lt 10 ]; then
echo "ALERTE: Mémoire libre à ${MEM_FREE}%"
fi

Résumé​

Dans ce chapitre, vous avez appris:

Diagnostic: Outils identification goulots d'étranglement
CPU: Priorités, affinity, limites
Mémoire: Swap, cache, limites
I/O: FS, scheduler, RAID
Kernel: sysctl, paramètres réseau/mémoire
Services: Désactiver inutiles, limites
Monitoring: Scripts, alertes performance


Prochaines Étapes​

Chapitre 12.3: Automatisation Complète
Fin du Cours: Récapitulatif


Chapitre créé le: Décembre 2024