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
@@ -12,8 +12,26 @@
|
||||
* 0019 迁移把数据并成了一个值。
|
||||
*
|
||||
* SQL 题不走这里,走 `judge/sql/`;流程图题走 AI 评分。
|
||||
*
|
||||
* 命令里的文件名都是相对沙箱工作目录(/w)的。编译错误因此是 `main.c:3:5: error`,
|
||||
* 不带目录;Python 的回溯会被解释器补成绝对路径 `/w/solution.py`,前端显示前去掉。
|
||||
* 限额(CPU 毫秒、墙钟毫秒、字节)的口径照搬 JudgeServer,怎么换算见 sandbox.ts。
|
||||
*/
|
||||
const defaultEnv = ['LANG=en_US.UTF-8', 'LANGUAGE=en_US:en', 'LC_ALL=en_US.UTF-8']
|
||||
export interface LanguageConfig {
|
||||
compile: {
|
||||
/** 学生代码写成的文件名 */
|
||||
srcName: string
|
||||
/** 编译产物。Python 没有产物,「编译」只是 py_compile 查一遍语法,运行的还是源文件 */
|
||||
exeName: string
|
||||
command: string[]
|
||||
maxCpuTime: number
|
||||
maxRealTime: number
|
||||
maxMemory: number
|
||||
}
|
||||
run: {
|
||||
command: string[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gcc-14 起这五类老写法从 warning 提成了 error,而 `-w` 只关警告、压不住 error:
|
||||
@@ -27,57 +45,47 @@ const defaultEnv = ['LANG=en_US.UTF-8', 'LANGUAGE=en_US:en', 'LC_ALL=en_US.UTF-8
|
||||
* 哪天决定「就是要学生写规范」,是删掉这几个开关,不是改镜像 —— 删之前先拿
|
||||
* docs/c-tutorials/verify-code.sh 全量过一遍教程。
|
||||
*/
|
||||
const cLooseErrors =
|
||||
'-Wno-error=implicit-function-declaration -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch -Wno-error=implicit-int'
|
||||
const cLooseErrors = [
|
||||
'-Wno-error=implicit-function-declaration',
|
||||
'-Wno-error=int-conversion',
|
||||
'-Wno-error=incompatible-pointer-types',
|
||||
'-Wno-error=return-mismatch',
|
||||
'-Wno-error=implicit-int',
|
||||
]
|
||||
|
||||
export const languageConfigs: Record<string, Record<string, unknown>> = {
|
||||
export const languageConfigs: Record<string, LanguageConfig> = {
|
||||
C: {
|
||||
template: '',
|
||||
compile: {
|
||||
src_name: 'main.c',
|
||||
exe_name: 'main',
|
||||
max_cpu_time: 3000,
|
||||
max_real_time: 10000,
|
||||
max_memory: 256 * 1024 * 1024,
|
||||
compile_command: `/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c17 ${cLooseErrors} {src_path} -lm -o {exe_path}`,
|
||||
},
|
||||
run: {
|
||||
command: '{exe_path}',
|
||||
seccomp_rule: { 'Standard IO': 'c_cpp', 'File IO': 'c_cpp_file_io' },
|
||||
env: defaultEnv,
|
||||
srcName: 'main.c',
|
||||
exeName: 'main',
|
||||
command: ['/usr/bin/gcc', '-DONLINE_JUDGE', '-O2', '-w', '-fmax-errors=3', '-std=c17', ...cLooseErrors, 'main.c', '-lm', '-o', 'main'],
|
||||
maxCpuTime: 3000,
|
||||
maxRealTime: 10000,
|
||||
maxMemory: 256 * 1024 * 1024,
|
||||
},
|
||||
run: { command: ['main'] },
|
||||
},
|
||||
'C++': {
|
||||
template: '',
|
||||
compile: {
|
||||
src_name: 'main.cpp',
|
||||
exe_name: 'main',
|
||||
max_cpu_time: 10000,
|
||||
max_real_time: 20000,
|
||||
max_memory: 1024 * 1024 * 1024,
|
||||
compile_command: '/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++20 {src_path} -lm -o {exe_path}',
|
||||
},
|
||||
run: {
|
||||
command: '{exe_path}',
|
||||
seccomp_rule: { 'Standard IO': 'c_cpp', 'File IO': 'c_cpp_file_io' },
|
||||
env: defaultEnv,
|
||||
srcName: 'main.cpp',
|
||||
exeName: 'main',
|
||||
command: ['/usr/bin/g++', '-DONLINE_JUDGE', '-O2', '-w', '-fmax-errors=3', '-std=c++20', 'main.cpp', '-lm', '-o', 'main'],
|
||||
maxCpuTime: 10000,
|
||||
maxRealTime: 20000,
|
||||
maxMemory: 1024 * 1024 * 1024,
|
||||
},
|
||||
run: { command: ['main'] },
|
||||
},
|
||||
Python: {
|
||||
template: '',
|
||||
compile: {
|
||||
src_name: 'solution.py',
|
||||
exe_name: 'solution.py',
|
||||
max_cpu_time: 3000,
|
||||
max_real_time: 10000,
|
||||
max_memory: 128 * 1024 * 1024,
|
||||
compile_command: '/usr/bin/python3 -m py_compile {src_path}',
|
||||
},
|
||||
run: {
|
||||
command: '/usr/bin/python3 -BS {exe_path}',
|
||||
seccomp_rule: 'general',
|
||||
env: defaultEnv,
|
||||
srcName: 'solution.py',
|
||||
exeName: 'solution.py',
|
||||
command: ['/usr/bin/python3', '-m', 'py_compile', 'solution.py'],
|
||||
maxCpuTime: 3000,
|
||||
maxRealTime: 10000,
|
||||
maxMemory: 128 * 1024 * 1024,
|
||||
},
|
||||
run: { command: ['/usr/bin/python3', '-BS', 'solution.py'] },
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user