fix: MySQL 空闲连接健康检查 + Gunicorn worker 保活,解决广播开才不卡
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,6 +16,14 @@ sleep 2
|
||||
systemctl is-active gunicorn-dianjing.service
|
||||
pgrep -cf 'gunicorn.*a_long_dianjing' || true
|
||||
|
||||
echo ""
|
||||
echo ">>> 安装 worker 保活 cron(空闲后不卡)"
|
||||
chmod +x deploy/gunicorn-warmup.sh
|
||||
cp deploy/gunicorn-warmup.cron /etc/cron.d/gunicorn-warmup
|
||||
chmod 644 /etc/cron.d/gunicorn-warmup
|
||||
bash deploy/gunicorn-warmup.sh
|
||||
echo " cron 已安装,每2分钟预热 worker"
|
||||
|
||||
echo ""
|
||||
echo ">>> 最近慢请求 (rt>=0.5s):"
|
||||
grep -a 'hqhd' "$NGINX_LOG" | awk 'match($0,/rt=([0-9.]+)/,a){if(a[1]+0>=0.5)print}' | tail -5
|
||||
|
||||
5
deploy/gunicorn-warmup.cron
Normal file
5
deploy/gunicorn-warmup.cron
Normal file
@@ -0,0 +1,5 @@
|
||||
# 每 2 分钟预热 Gunicorn worker,解决「空闲后第一下卡、有广播/并发反而不卡」
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
*/2 * * * * root /opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django/deploy/gunicorn-warmup.sh >/dev/null 2>&1
|
||||
16
deploy/gunicorn-warmup.sh
Normal file
16
deploy/gunicorn-warmup.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# 每 2 分钟 ping 一次 Gunicorn,避免 worker/数据库连接空闲后「第一下卡」
|
||||
# 安装: cp deploy/gunicorn-warmup.cron /etc/cron.d/gunicorn-warmup && chmod 644 /etc/cron.d/gunicorn-warmup
|
||||
|
||||
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
|
||||
cd "$DJANGO_DIR"
|
||||
|
||||
# 6 个 worker 各打一次,保持连接池温热
|
||||
for _ in 1 2 3 4 5 6; do
|
||||
curl -s -o /dev/null --max-time 3 http://127.0.0.1:8001/ &
|
||||
done
|
||||
wait
|
||||
|
||||
# 顺带测一条需连库的轻量配置接口(无需 token 的会 401/404,但会走 Django+MySQL)
|
||||
curl -s -o /dev/null --max-time 5 -X POST http://127.0.0.1:8001/hqhd/peizhi/qdpzhq \
|
||||
-H 'Content-Type: application/json' -d '{}' 2>/dev/null || true
|
||||
Reference in New Issue
Block a user