Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
121 lines
3.5 KiB
Python
121 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy response-speed optimizations; measure hot API latency on VPS."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
REPO = "/opt/douyinWEB"
|
|
|
|
FILES = [
|
|
"backend/app/db.py",
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/yt_assign_db.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/host_metrics.py",
|
|
"backend/app/douyin_live.py",
|
|
"frontend/src/lib/realtime.ts",
|
|
"frontend/src/lib/douyinLive.ts",
|
|
"frontend/src/lib/youtubeLive.ts",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
"frontend/src/components/HostResourceBar.tsx",
|
|
]
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
|
|
print("uploaded", rel)
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
systemctl restart douyinweb-api
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-api
|
|
systemctl is-active douyinweb-web
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
import time
|
|
from app.db import init_db, get_settings_map
|
|
from app import youtube_relay_pipeline, youtube_neko, yt_assign_db, host_metrics, douyin_live
|
|
|
|
init_db()
|
|
|
|
# settings cache: second call should be near-instant
|
|
t0 = time.perf_counter()
|
|
get_settings_map()
|
|
t1 = time.perf_counter()
|
|
get_settings_map()
|
|
t2 = time.perf_counter()
|
|
print(f"settings_ms first={((t1-t0)*1000):.1f} cached={((t2-t1)*1000):.1f}")
|
|
|
|
# neko list: batch + no curl
|
|
t0 = time.perf_counter()
|
|
rows = youtube_neko.list_instances(5, check_http=False)
|
|
t1 = time.perf_counter()
|
|
rows2 = youtube_neko.list_instances(5, check_http=False)
|
|
t2 = time.perf_counter()
|
|
print(f"neko_list_ms first={((t1-t0)*1000):.1f} cached={((t2-t1)*1000):.1f} n={len(rows)} ready={[r.get('ready') for r in rows]}")
|
|
|
|
# relay status: warm + cached
|
|
pipe = youtube_relay_pipeline.youtube_relay_pipeline
|
|
t0 = time.perf_counter()
|
|
st = pipe.status()
|
|
t1 = time.perf_counter()
|
|
st2 = pipe.status()
|
|
t2 = time.perf_counter()
|
|
print(f"relay_status_ms first={((t1-t0)*1000):.1f} cached={((t2-t1)*1000):.1f} groups={st.get('group_count')} pushing={st.get('pushing_count')}")
|
|
|
|
t0 = time.perf_counter()
|
|
hm = host_metrics.snapshot()
|
|
t1 = time.perf_counter()
|
|
hm2 = host_metrics.snapshot()
|
|
t2 = time.perf_counter()
|
|
print(f"host_metrics_ms first={((t1-t0)*1000):.1f} cached={((t2-t1)*1000):.1f} cpu={hm.get('cpu_percent')}")
|
|
|
|
t0 = time.perf_counter()
|
|
dm = douyin_live.build_live_map()
|
|
t1 = time.perf_counter()
|
|
dm2 = douyin_live.build_live_map()
|
|
t2 = time.perf_counter()
|
|
print(f"douyin_live_ms first={((t1-t0)*1000):.1f} cached={((t2-t1)*1000):.1f} live={dm.get('live_count')}")
|
|
|
|
# featured_only groups
|
|
t0 = time.perf_counter()
|
|
g = yt_assign_db.list_groups(featured_only=True)
|
|
t1 = time.perf_counter()
|
|
print(f"groups_featured_only_ms={((t1-t0)*1000):.1f} n={len(g)}")
|
|
PY
|
|
"""
|
|
print("remote deploy…")
|
|
stdin, stdout, stderr = c.exec_command(cmd, timeout=300)
|
|
out = stdout.read().decode("utf-8", "replace")
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
code = stdout.channel.recv_exit_status()
|
|
print(out)
|
|
if err.strip():
|
|
print("STDERR:", err[-2000:])
|
|
print("exit", code)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main() or 0)
|