mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01: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,
|
SettingModel, StorageModel, SystemModel, TaskModel,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { langs } from 'hydrooj/src/model/setting';
|
import { langs } from 'hydrooj/src/model/setting';
|
||||||
import { compilerVersions } from '../compiler';
|
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { FormatError, SystemError } from '../error';
|
import { FormatError, SystemError } from '../error';
|
||||||
|
import { compilerVersions, stackSize } from '../info';
|
||||||
import { Context } from '../judge/interface';
|
import { Context } from '../judge/interface';
|
||||||
import logger from '../log';
|
import logger from '../log';
|
||||||
import { versionCheck } from '../sandbox';
|
import { versionCheck } from '../sandbox';
|
||||||
@@ -96,19 +96,26 @@ export async function postInit(ctx) {
|
|||||||
};
|
};
|
||||||
const parallelism = Math.max(getConfig('parallelism'), 2);
|
const parallelism = Math.max(getConfig('parallelism'), 2);
|
||||||
const taskConsumer = TaskModel.consume({ type: 'judge' }, handle, true, parallelism);
|
const taskConsumer = TaskModel.consume({ type: 'judge' }, handle, true, parallelism);
|
||||||
function collectCompilerInfo() {
|
async function collectInfo() {
|
||||||
const coll = db.collection('status');
|
const coll = db.collection('status');
|
||||||
compilerVersions(langs).then((compilers) => coll.updateOne(
|
const compilers = await compilerVersions(langs);
|
||||||
|
await coll.updateOne(
|
||||||
{ mid: info.mid, type: 'server' },
|
{ mid: info.mid, type: 'server' },
|
||||||
{ $set: { compilers } },
|
{ $set: { compilers } },
|
||||||
{ upsert: true },
|
{ 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', () => {
|
ctx.on('system/setting', () => {
|
||||||
taskConsumer.setConcurrency(Math.max(getConfig('parallelism'), 2));
|
taskConsumer.setConcurrency(Math.max(getConfig('parallelism'), 2));
|
||||||
collectCompilerInfo();
|
collectInfo();
|
||||||
});
|
});
|
||||||
collectCompilerInfo();
|
collectInfo();
|
||||||
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
|
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
|
||||||
TaskModel.consume({ type: 'generate' }, handle);
|
TaskModel.consume({ type: 'generate' }, handle);
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@ import { fs, pipeRequest } from '@hydrooj/utils';
|
|||||||
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
||||||
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
||||||
import type { JudgeResultBody } from 'hydrooj';
|
import type { JudgeResultBody } from 'hydrooj';
|
||||||
import { compilerVersions } from '../compiler';
|
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { FormatError, SystemError } from '../error';
|
import { FormatError, SystemError } from '../error';
|
||||||
|
import { compilerVersions, stackSize as getStackSize } from '../info';
|
||||||
import { Session } from '../interface';
|
import { Session } from '../interface';
|
||||||
import log from '../log';
|
import log from '../log';
|
||||||
import { JudgeTask } from '../task';
|
import { JudgeTask } from '../task';
|
||||||
@@ -184,7 +184,8 @@ export default class Hydro implements Session {
|
|||||||
? JSON.stringify({ key: 'config', ...config })
|
? JSON.stringify({ key: 'config', ...config })
|
||||||
: '{"key":"ping"}';
|
: '{"key":"ping"}';
|
||||||
let compilers = {};
|
let compilers = {};
|
||||||
let compilerVersionCallback = () => { };
|
let sendStatus = () => { };
|
||||||
|
let stackSize = 0;
|
||||||
this.ws.on('message', (data) => {
|
this.ws.on('message', (data) => {
|
||||||
if (data.toString() === 'ping') {
|
if (data.toString() === 'ping') {
|
||||||
this.ws.send('pong');
|
this.ws.send('pong');
|
||||||
@@ -193,9 +194,13 @@ export default class Hydro implements Session {
|
|||||||
const request = JSON.parse(data.toString());
|
const request = JSON.parse(data.toString());
|
||||||
if (request.language) {
|
if (request.language) {
|
||||||
this.language = request.language;
|
this.language = request.language;
|
||||||
compilerVersions(this.language).then((res) => {
|
Promise.allSettled([
|
||||||
compilers = res;
|
compilerVersions(this.language),
|
||||||
compilerVersionCallback();
|
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)));
|
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"}');
|
this.ws.send('{"key":"start"}');
|
||||||
if (!this.config.noStatus) {
|
if (!this.config.noStatus) {
|
||||||
const info = await sysinfo.get();
|
const info = await sysinfo.get();
|
||||||
this.ws.send(JSON.stringify({ key: 'status', info: { ...info } }));
|
this.ws.send(JSON.stringify({ key: 'status', info: { ...info, stackSize } }));
|
||||||
compilerVersionCallback = () => {
|
sendStatus = () => this.ws.send(JSON.stringify({ key: 'status', info: { ...info, compilers, stackSize } }));
|
||||||
this.ws.send(JSON.stringify({ key: 'status', info: { ...info, compilers } }));
|
const interval = setInterval(async () => {
|
||||||
};
|
|
||||||
setInterval(async () => {
|
|
||||||
const [mid, inf] = await sysinfo.update();
|
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);
|
}, 1200000);
|
||||||
|
let stopped = false;
|
||||||
|
const stop = () => {
|
||||||
|
if (!stopped) clearInterval(interval);
|
||||||
|
stopped = true;
|
||||||
|
};
|
||||||
|
this.ws.on('close', stop);
|
||||||
|
this.ws.on('error', stop);
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,3 +16,13 @@ export async function compilerVersions(langs: Record<string, LangConfig>) {
|
|||||||
}
|
}
|
||||||
return result;
|
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();
|
const config = await client.config();
|
||||||
sandboxCgroup = config.runnerConfig?.cgroupType || 0;
|
sandboxCgroup = config.runnerConfig?.cgroupType || 0;
|
||||||
} catch (e) {
|
} 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!');
|
else reportError('Your sandbox version is tooooooo low! Please upgrade!');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user