perf: expand gateway capacity and prevent receipt replay

This commit is contained in:
hectorzhao
2026-08-25 16:08:30 +08:00
parent 761c123b65
commit 9292352be1
48 changed files with 2001 additions and 144 deletions
+37 -1
View File
@@ -61,6 +61,16 @@ if [[ "${GATEWAY_CALLBACK_SEPARATE_PROCESS_ENABLED:-false}" == "true" ]]; then
exit 1
fi
fi
if [[ "${GATEWAY_PROTOCOL_LOG_STREAM_ENABLED:-false}" == "true" && ! "${API_PROTOCOL_LOG_DB_POOL_MAX:-}" =~ ^[1-9][0-9]*$ ]]; then
echo "API_PROTOCOL_LOG_DB_POOL_MAX must be a positive integer when protocol log Stream writing is enabled." >&2
exit 1
fi
if [[ "${GATEWAY_CALLBACK_BATCH_ENABLED:-false}" == "true" ]]; then
if [[ ! "${GATEWAY_CALLBACK_BATCH_SIZE:-}" =~ ^[1-9][0-9]*$ || "${GATEWAY_CALLBACK_BATCH_SIZE}" -gt 100 ]]; then
echo "GATEWAY_CALLBACK_BATCH_SIZE must be between 1 and 100." >&2
exit 1
fi
fi
if [[ -z "${CMPP_PUBLIC_HOST:-}" || ! "${CMPP_PUBLIC_PORT:-}" =~ ^[1-9][0-9]*$ ]]; then
echo "CMPP_PUBLIC_HOST and a positive CMPP_PUBLIC_PORT are required in $ENV_FILE; these are the customer-facing CMPP endpoint." >&2
@@ -97,7 +107,7 @@ PROD_ADMIN_CREDENTIAL_FILE="$ADMIN_CREDENTIAL_FILE" node tools/deploy/ensure-pro
chmod 600 "$ADMIN_CREDENTIAL_FILE" || true
echo "[deploy] Ensuring runtime log directories"
install -d -m 0755 "$APP_DIR/logs/api" "$APP_DIR/logs/send-worker" "$APP_DIR/logs/submit-outbox" "$APP_DIR/logs/gateway-callback" "$APP_DIR/logs/gateway"
install -d -m 0755 "$APP_DIR/logs/api" "$APP_DIR/logs/send-worker" "$APP_DIR/logs/submit-outbox" "$APP_DIR/logs/gateway-callback" "$APP_DIR/logs/protocol-log-worker" "$APP_DIR/logs/gateway"
echo "[deploy] Installing split API and send-worker services"
node_bin="$(command -v node)"
@@ -163,6 +173,26 @@ RestartSec=5
StandardOutput=append:$APP_DIR/logs/gateway-callback/stdout.log
StandardError=append:$APP_DIR/logs/gateway-callback/stderr.log
[Install]
WantedBy=multi-user.target
EOF
cat >/etc/systemd/system/cmpp-protocol-log-worker.service <<EOF
[Unit]
Description=CMPP protocol log Redis Stream batch writer
After=network.target postgresql.service redis.service
[Service]
User=cmpp-api
Group=cmpp-security
WorkingDirectory=$APP_DIR/api
EnvironmentFile=$ENV_FILE
Environment=CMPP_PROCESS_ROLE=protocol-log-worker
ExecStart=$node_bin dist/protocol-log-worker.js
Restart=always
RestartSec=5
StandardOutput=append:$APP_DIR/logs/protocol-log-worker/stdout.log
StandardError=append:$APP_DIR/logs/protocol-log-worker/stderr.log
[Install]
WantedBy=multi-user.target
EOF
@@ -212,6 +242,12 @@ if [[ "${GATEWAY_CALLBACK_SEPARATE_PROCESS_ENABLED:-false}" == "true" ]]; then
else
systemctl disable --now cmpp-gateway-callback 2>/dev/null || true
fi
if [[ "${GATEWAY_PROTOCOL_LOG_STREAM_ENABLED:-false}" == "true" ]]; then
systemctl enable --now cmpp-protocol-log-worker
systemctl restart cmpp-protocol-log-worker
else
systemctl disable --now cmpp-protocol-log-worker 2>/dev/null || true
fi
# Gateway is restarted after the callback listener so supplier events never point
# at a callback port that has not completed Nest/Prisma initialization.
systemctl restart cmpp-gateway