perf(core): eliminate PHP session file lock contention on API/metrics, tune PHP-FPM pool, and remove redundant Keepalived restarts on sync
This commit is contained in:
1 parent
0b654c885c
commit
c93b52d99c
3 files changed
+34
-13
No files matched your search
+10
@@ -524,6 +524,16 @@ chmod +x /etc/profile.d/nexus-motd.sh
|
||||
echo -e "${C_GREEN}[8/8] Démarrage et activation des services système...${C_RESET}"
|
||||
systemctl daemon-reload
|
||||
|
||||
# Optimisation de la réserve de processus PHP-FPM pour supporter la télémétrie temps réel et le cluster HA
|
||||
for pool in /etc/php/*/fpm/pool.d/www.conf; do
|
||||
if [ -f "$pool" ]; then
|
||||
sed -i 's/^pm.max_children = .*/pm.max_children = 25/' "$pool"
|
||||
sed -i 's/^pm.start_servers = .*/pm.start_servers = 4/' "$pool"
|
||||
sed -i 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 2/' "$pool"
|
||||
sed -i 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 6/' "$pool"
|
||||
fi
|
||||
done
|
||||
|
||||
# Redémarrage PHP-FPM (rechargement de l'appartenance au groupe asterisk)
|
||||
systemctl restart php*-fpm 2>/dev/null || true
|
||||
PHP_SVC=$(systemctl list-unit-files --type=service 2>/dev/null | grep -E "php.*-fpm" | awk '{print $1}' | head -n 1 || echo "php8.4-fpm")
|
||||
|
||||
+17
-10
@@ -42,7 +42,6 @@ header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
|
||||
try {
|
||||
$db = Database::getConnection();
|
||||
Auth::startSession();
|
||||
|
||||
$action = trim((string)($_GET['action'] ?? ''));
|
||||
$rawBody = file_get_contents('php://input');
|
||||
@@ -51,6 +50,23 @@ try {
|
||||
$payload = $_POST;
|
||||
}
|
||||
|
||||
// Action inter-serveurs réplication Cluster (authentifiée par signature HMAC - aucune session requise)
|
||||
if ($action === 'cluster_receive_sync') {
|
||||
$signature = $_SERVER['HTTP_X_NEXUS_CLUSTER_SIGNATURE'] ?? '';
|
||||
$cm = new ClusterManager($db);
|
||||
$res = $cm->receiveSyncPayload($rawBody ?: '', $signature);
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
|
||||
Auth::startSession();
|
||||
|
||||
// Pour les requêtes en lecture seule fréquente (polling métriques / statut), libérer immédiatement le verrou de session
|
||||
// Cela évite de saturer les workers PHP-FPM par des verrous de fichiers sessions concurrents
|
||||
if (session_status() === PHP_SESSION_ACTIVE && ($action === 'get_metrics' || $action === 'cluster_status' || $action === 'get_system_info')) {
|
||||
session_write_close();
|
||||
}
|
||||
|
||||
// Actions publiques (Login / Logout)
|
||||
if ($action === 'login') {
|
||||
$username = trim((string)($payload['username'] ?? ''));
|
||||
@@ -86,15 +102,6 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Action inter-serveurs réplication Cluster (authentifiée par signature HMAC)
|
||||
if ($action === 'cluster_receive_sync') {
|
||||
$rawBody = file_get_contents('php://input') ?: '';
|
||||
$signature = $_SERVER['HTTP_X_NEXUS_CLUSTER_SIGNATURE'] ?? '';
|
||||
$cm = new ClusterManager($db);
|
||||
$res = $cm->receiveSyncPayload($rawBody, $signature);
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Toutes les autres actions requièrent une session authentifiée
|
||||
if (!Auth::isAuthenticated()) {
|
||||
|
||||
@@ -564,13 +564,14 @@ class ClusterManager
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Expect:', // Désactive l'en-tête Expect: 100-continue pour éviter les blocages intermédiaires
|
||||
'X-Nexus-Cluster-Signature: ' . $signature,
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
@@ -754,10 +755,13 @@ class ClusterManager
|
||||
shell_exec('/usr/sbin/asterisk -rx "pjsip send unregister *" 2>/dev/null || true');
|
||||
}
|
||||
|
||||
// Si le cluster est actif, actualiser le service Keepalived
|
||||
// Si le cluster est activé mais que Keepalived n'est pas encore démarré, le démarrer
|
||||
if (!empty($localClusterSettings['enabled'])) {
|
||||
$keepalivedRunning = trim((string)shell_exec('pidof keepalived 2>/dev/null')) !== '';
|
||||
if (!$keepalivedRunning) {
|
||||
$this->applyKeepalivedConfig();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
|
||||
Reference in new issue
Block a user