fix: 修復 Worker 退出時執行緒卡住導致 timeout 問題
- 增加 graceful_timeout 從 10s 到 30s,給予執行緒足夠清理時間 - worker_exit hook 新增停止背景同步執行緒邏輯 - 調整 SLOW_QUERY_THRESHOLD 預設值為 5.0s (即時視圖查詢通常需 2-5s) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -112,8 +112,9 @@ CIRCUIT_BREAKER_WINDOW_SIZE=10
|
||||
# ============================================================
|
||||
# Performance Metrics Configuration
|
||||
# ============================================================
|
||||
# Slow query threshold in seconds (default: 1.0)
|
||||
SLOW_QUERY_THRESHOLD=1.0
|
||||
# Slow query threshold in seconds (default: 5.0)
|
||||
# Note: Real-time Oracle views may take 2-5s per query, set threshold accordingly
|
||||
SLOW_QUERY_THRESHOLD=5.0
|
||||
|
||||
# ============================================================
|
||||
# SQLite Log Store Configuration
|
||||
|
||||
@@ -7,7 +7,7 @@ worker_class = "gthread"
|
||||
|
||||
# Timeout settings - critical for dashboard stability
|
||||
timeout = 65 # Worker timeout: must be > call_timeout (55s)
|
||||
graceful_timeout = 10 # Graceful shutdown timeout (reduced for faster restart)
|
||||
graceful_timeout = 30 # Graceful shutdown timeout (enough for thread cleanup)
|
||||
keepalive = 5 # Keep-alive connections timeout
|
||||
|
||||
# Worker lifecycle management - prevent state accumulation
|
||||
@@ -20,7 +20,17 @@ max_requests_jitter = 100 # Random jitter to prevent simultaneous restarts
|
||||
# ============================================================
|
||||
|
||||
def worker_exit(server, worker):
|
||||
"""Clean up database connections when worker exits."""
|
||||
"""Clean up background threads and database connections when worker exits."""
|
||||
# Stop background sync threads first
|
||||
try:
|
||||
from mes_dashboard.services.realtime_equipment_cache import (
|
||||
stop_equipment_status_sync_worker
|
||||
)
|
||||
stop_equipment_status_sync_worker()
|
||||
except Exception as e:
|
||||
server.log.warning(f"Error stopping equipment sync worker: {e}")
|
||||
|
||||
# Then dispose database connections
|
||||
try:
|
||||
from mes_dashboard.core.database import dispose_engine
|
||||
dispose_engine()
|
||||
|
||||
Reference in New Issue
Block a user