feat: 增加每日内存回收与 malloc arena 限制
流媒体会话会在 glibc malloc arena 中留下大量不归还操作系统的冷匿名内存,实测单个 服务可累积到 2.5 GB 并占满整个 swap 文件(33 个 64/128 MB 匿名段,空闲时不增长, 随会话单调抬升)。本次从根因与兜底两侧处理: - systemd/maa-online-server.service: 设置 MALLOC_ARENA_MAX=2,把线程 arena 数量 从 8xCPU 压到 2,抑制 arena 膨胀 - systemd/maa-daily.service: 单元结束时经 ExecStopPost 重启 API 服务,回收当次会话残留 - systemd/maa-online-recycle.service, maa-online-recycle.timer: 新增每日 03:59(游戏 每日刷新前)独立回收定时器,错开更新与日常任务窗口,Persistent=false 避免补跑撞车 - bin/maa-online-can-recycle: 回收守卫,检测日常任务(systemd 单元或手工运行)是否 进行中,是则跳过回收,避免重启打断任务 - bin/maa-online-install-systemd: 安装并启用新增的回收单元 - README.md, user_config/README.md: 补充内存回收机制与定时器说明
This commit is contained in:
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Guard for maa-online-recycle.service.
|
||||
#
|
||||
# Exit 0 when it is safe to restart the cloud game API server, exit 1 when a
|
||||
# daily run is in progress. Restarting the server underneath a running task
|
||||
# breaks that attempt, and the recycle timer fires right next to the daily
|
||||
# window, so the recycle must never race with it.
|
||||
set -uo pipefail
|
||||
|
||||
state=$(systemctl show -p ActiveState --value maa-daily.service 2>/dev/null || echo unknown)
|
||||
case "$state" in
|
||||
active|activating|reloading|deactivating)
|
||||
echo "maa-daily.service is '$state'; skipping recycle" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Cover a run started by hand (bin/maa-online-daily-run outside systemd).
|
||||
if pgrep -x maa >/dev/null 2>&1; then
|
||||
echo "a maa task is running; skipping recycle" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -7,7 +7,7 @@ set -euo pipefail
|
||||
ROOT="${MAA_ONLINE_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
||||
SRC="$ROOT/systemd"
|
||||
DST="${MAA_ONLINE_SYSTEMD_DIR:-/etc/systemd/system}"
|
||||
UNITS=(maa-online-server.service maa-daily.service maa-daily.timer maa-update.service maa-update.timer)
|
||||
UNITS=(maa-online-server.service maa-daily.service maa-daily.timer maa-update.service maa-update.timer maa-online-recycle.service maa-online-recycle.timer)
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "error: must run as root (writes to $DST)" >&2
|
||||
@@ -25,15 +25,15 @@ done
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now maa-online-server.service
|
||||
systemctl enable maa-daily.timer maa-update.timer
|
||||
systemctl start maa-daily.timer maa-update.timer
|
||||
systemctl enable maa-daily.timer maa-update.timer maa-online-recycle.timer
|
||||
systemctl start maa-daily.timer maa-update.timer maa-online-recycle.timer
|
||||
|
||||
echo
|
||||
systemctl --no-pager list-timers maa-daily.timer maa-update.timer
|
||||
systemctl --no-pager list-timers maa-daily.timer maa-update.timer maa-online-recycle.timer
|
||||
cat <<EOF
|
||||
|
||||
MAA Online systemd units are active.
|
||||
server log: journalctl -u maa-online-server -f
|
||||
daily log: journalctl -u maa-daily -n 50
|
||||
next runs: systemctl list-timers maa-daily.timer maa-update.timer
|
||||
next runs: systemctl list-timers maa-daily.timer maa-update.timer maa-online-recycle.timer
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user