mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
judge: add stack size report
This commit is contained in:
4 files changed
+50
-18
No files matched your search
@@ -8,9 +8,9 @@ import {
|
||||
SettingModel, StorageModel, SystemModel, TaskModel,
|
||||
} from 'hydrooj';
|
||||
import { langs } from 'hydrooj/src/model/setting';
|
||||
import { compilerVersions } from '../compiler';
|
||||
import { getConfig } from '../config';
|
||||
import { FormatError, SystemError } from '../error';
|
||||
import { compilerVersions, stackSize } from '../info';
|
||||
import { Context } from '../judge/interface';
|
||||
import logger from '../log';
|
||||
import { versionCheck } from '../sandbox';
|
||||
@@ -96,19 +96,26 @@ export async function postInit(ctx) {
|
||||
};
|
||||
const parallelism = Math.max(getConfig('parallelism'), 2);
|
||||
const taskConsumer = TaskModel.consume({ type: 'judge' }, handle, true, parallelism);
|
||||
function collectCompilerInfo() {
|
||||
async function collectInfo() {
|
||||
const coll = db.collection('status');
|
||||
compilerVersions(langs).then((compilers) => coll.updateOne(
|
||||
const compilers = await compilerVersions(langs);
|
||||
await coll.updateOne(
|
||||
{ mid: info.mid, type: 'server' },
|
||||
{ $set: { compilers } },
|
||||
{ upsert: true },
|
||||
)).catch((e) => logger.error(e));
|
||||
);
|
||||
const size = await stackSize();
|
||||
await coll.updateOne(
|
||||
{ mid: info.mid, type: 'server' },
|
||||
{ $set: { stackSize: size } },
|
||||
{ upsert: true },
|
||||
);
|
||||
}
|
||||
ctx.on('system/setting', () => {
|
||||
taskConsumer.setConcurrency(Math.max(getConfig('parallelism'), 2));
|
||||
collectCompilerInfo();
|
||||
collectInfo();
|
||||
});
|
||||
collectCompilerInfo();
|
||||
collectInfo();
|
||||
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
|
||||
TaskModel.consume({ type: 'generate' }, handle);
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import { fs, pipeRequest } from '@hydrooj/utils';
|
||||
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
||||
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
||||
import type { JudgeResultBody } from 'hydrooj';
|
||||
import { compilerVersions } from '../compiler';
|
||||
import { getConfig } from '../config';
|
||||
import { FormatError, SystemError } from '../error';
|
||||
import { compilerVersions, stackSize as getStackSize } from '../info';
|
||||
import { Session } from '../interface';
|
||||
import log from '../log';
|
||||
import { JudgeTask } from '../task';
|
||||
@@ -184,7 +184,8 @@ export default class Hydro implements Session {
|
||||
? JSON.stringify({ key: 'config', ...config })
|
||||
: '{"key":"ping"}';
|
||||
let compilers = {};
|
||||
let compilerVersionCallback = () => { };
|
||||
let sendStatus = () => { };
|
||||
let stackSize = 0;
|
||||
this.ws.on('message', (data) => {
|
||||
if (data.toString() === 'ping') {
|
||||
this.ws.send('pong');
|
||||
@@ -193,9 +194,13 @@ export default class Hydro implements Session {
|
||||
const request = JSON.parse(data.toString());
|
||||
if (request.language) {
|
||||
this.language = request.language;
|
||||
compilerVersions(this.language).then((res) => {
|
||||
compilers = res;
|
||||
compilerVersionCallback();
|
||||
Promise.allSettled([
|
||||
compilerVersions(this.language),
|
||||
getStackSize(),
|
||||
]).then(([compiler, stack]) => {
|
||||
compilers = compiler.status === 'fulfilled' ? compiler.value : {};
|
||||
stackSize = stack.status === 'fulfilled' ? stack.value : 0;
|
||||
sendStatus();
|
||||
});
|
||||
}
|
||||
if (request.task) queue.add(() => new JudgeTask(this, request.task).handle().catch((e) => log.error(e)));
|
||||
@@ -214,14 +219,24 @@ export default class Hydro implements Session {
|
||||
this.ws.send('{"key":"start"}');
|
||||
if (!this.config.noStatus) {
|
||||
const info = await sysinfo.get();
|
||||
this.ws.send(JSON.stringify({ key: 'status', info: { ...info } }));
|
||||
compilerVersionCallback = () => {
|
||||
this.ws.send(JSON.stringify({ key: 'status', info: { ...info, compilers } }));
|
||||
};
|
||||
setInterval(async () => {
|
||||
this.ws.send(JSON.stringify({ key: 'status', info: { ...info, stackSize } }));
|
||||
sendStatus = () => this.ws.send(JSON.stringify({ key: 'status', info: { ...info, compilers, stackSize } }));
|
||||
const interval = setInterval(async () => {
|
||||
const [mid, inf] = await sysinfo.update();
|
||||
this.ws.send(JSON.stringify({ key: 'status', info: { mid, ...inf, compilers } }));
|
||||
this.ws.send(JSON.stringify({
|
||||
key: 'status',
|
||||
info: {
|
||||
mid, ...inf, compilers, stackSize,
|
||||
},
|
||||
}));
|
||||
}, 1200000);
|
||||
let stopped = false;
|
||||
const stop = () => {
|
||||
if (!stopped) clearInterval(interval);
|
||||
stopped = true;
|
||||
};
|
||||
this.ws.on('close', stop);
|
||||
this.ws.on('error', stop);
|
||||
}
|
||||
resolve(null);
|
||||
});
|
||||
|
||||
@@ -16,3 +16,13 @@ export async function compilerVersions(langs: Record<string, LangConfig>) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function stackSize() {
|
||||
const res = await runQueued('/bin/bash -c "ulimit -s"', {
|
||||
copyIn: {},
|
||||
time: 10000,
|
||||
memory: 256,
|
||||
}, 'stackSize', 5);
|
||||
if (res.stderr) return -1;
|
||||
return +res.stdout;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ export async function versionCheck(reportWarn: (str: string) => void, reportErro
|
||||
const config = await client.config();
|
||||
sandboxCgroup = config.runnerConfig?.cgroupType || 0;
|
||||
} catch (e) {
|
||||
if (e?.syscall === 'connect') reportError('Connecting to sandbox failed, please check sandbox_host config and if your sandbox is running.');
|
||||
if (e?.code === 'ECONNREFUSED') reportError('Failed to connect to sandbox, please check sandbox_host config and if your sandbox is running.');
|
||||
else reportError('Your sandbox version is tooooooo low! Please upgrade!');
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user