refactor(判题机): 换成 go-judge,空闲内存从几百 MB 降到 16 MB
原来的 JudgeServer 按核数起 gunicorn worker、每份提交再按核数开进程池,空闲内存跟着核数走
(2 核 52MB、16 核 305MB)。换成 go-judge 后空闲 16MB,同一批提交判题中 80–100MB(原来约 370MB)。
go-judge 只管在沙箱里跑命令,编译、逐点运行、比对输出、定状态码搬到 judge/sandbox.ts,
口径逐条照搬 JudgeServer,出参形状不变。拿生产库真实提交新旧逐点对比:C 2000 份 1989 一致、
C++ 891 份 890 一致、Python 2000 份全一致;不一致的是 system("pause")(现在不再判运行时错误)、
未定义行为、endl 死循环打印(运行时错误变运行超时),见 docker/judge/README.md。
- 判题容器改成 privileged(go-judge 要自己建 cgroup),镜像 oj2-judge-3
- 心跳改由 worker 每 5 秒问判题机 /version 代记,删掉 /api/judge-server/heartbeat
- 前端统一用 stripJudgePath 去掉判题机工作目录(新的 /w/ 和旧的 /judger/run/)
- 提交前编译检查只编译不运行
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8427475337
commit
37e971b6b4
30 files changed
+881
-592
No files matched your search
+1
-7
@@ -108,14 +108,9 @@ pgver=$(cat "$pgver_file")
|
||||
[ "$pgver" = 18 ] || die "$data_dir/postgresql 是 PostgreSQL $pgver 的数据目录,但 compose 里是 postgres:18-alpine,起不来。"
|
||||
ok "数据目录 $data_dir/postgresql(PostgreSQL $pgver)"
|
||||
|
||||
# ③ 判题机运行目录:不设就是 $DATA_DIR/judge_server
|
||||
judge_dir=$(grep -E '^JUDGE_STATE_DIR=' docker/.env | tail -1 | cut -d= -f2- || true)
|
||||
ok "判题机运行目录 ${judge_dir:-$data_dir/judge_server}"
|
||||
|
||||
# ④ 判题镜像是自建的(上游 JudgeServer 停更,官方镜像的编译器停在 gcc-13),
|
||||
# ③ 判题镜像是自建的(go-judge 的二进制 + 我们要的 gcc / python),
|
||||
# registry 上没有这个 tag。忘了 docker load 的话,要到「起栈」那步 compose 去 pull
|
||||
# 才失败 —— 不如在这里就把该跑的三条命令说清楚。
|
||||
# 回滚到官方镜像时这段自动跳过:那个 tag 是 pull 得到的。
|
||||
judge_image=$(grep -m1 -E '^[[:space:]]*image: oj2-judge' <<<"$cfg" | awk '{print $2}' || true)
|
||||
if [ -n "$judge_image" ]; then
|
||||
docker image inspect "$judge_image" >/dev/null 2>&1 \
|
||||
@@ -134,7 +129,6 @@ ok "对外端口 $port"
|
||||
[ "$CHECK_ONLY" -eq 0 ] || { printf '\n\033[1;32m✅ 自检通过(--check,没动容器)\033[0m\n'; exit 0; }
|
||||
|
||||
# ---------------------------------------------------------------- 起栈
|
||||
mkdir -p "$judge_dir/log" "$judge_dir/run"
|
||||
|
||||
if [ "$BUILD" -eq 1 ]; then
|
||||
say "构建镜像(首次约 5 分钟,之后走缓存很快)"
|
||||
|
||||
Reference in new issue
Block a user