timeout is wall-time for backward compatibility
This commit is contained in:
parent
1a1236dcbe
commit
2e00325163
|
@ -61,6 +61,8 @@ function get_job(body) {
|
||||||
run_memory_limit,
|
run_memory_limit,
|
||||||
run_timeout,
|
run_timeout,
|
||||||
compile_timeout,
|
compile_timeout,
|
||||||
|
run_cpu_time,
|
||||||
|
compile_cpu_time,
|
||||||
} = body;
|
} = body;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -106,7 +108,7 @@ function get_job(body) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const constraint of ['memory_limit', 'timeout']) {
|
for (const constraint of ['memory_limit', 'timeout', 'cpu_time']) {
|
||||||
for (const type of ['compile', 'run']) {
|
for (const type of ['compile', 'run']) {
|
||||||
const constraint_name = `${type}_${constraint}`;
|
const constraint_name = `${type}_${constraint}`;
|
||||||
const constraint_value = body[constraint_name];
|
const constraint_value = body[constraint_name];
|
||||||
|
@ -145,6 +147,10 @@ function get_job(body) {
|
||||||
run: run_timeout ?? rt.timeouts.run,
|
run: run_timeout ?? rt.timeouts.run,
|
||||||
compile: compile_timeout ?? rt.timeouts.compile,
|
compile: compile_timeout ?? rt.timeouts.compile,
|
||||||
},
|
},
|
||||||
|
cpu_times: {
|
||||||
|
run: run_cpu_time ?? rt.cpu_times.run,
|
||||||
|
compile: compile_cpu_time ?? rt.cpu_times.compile,
|
||||||
|
},
|
||||||
memory_limits: {
|
memory_limits: {
|
||||||
run: run_memory_limit ?? rt.memory_limits.run,
|
run: run_memory_limit ?? rt.memory_limits.run,
|
||||||
compile: compile_memory_limit ?? rt.memory_limits.compile,
|
compile: compile_memory_limit ?? rt.memory_limits.compile,
|
||||||
|
@ -272,6 +278,7 @@ router.post('/execute', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
job = await get_job(req.body);
|
job = await get_job(req.body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.error({ error });
|
||||||
return res.status(400).json(error);
|
return res.status(400).json(error);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -90,6 +90,18 @@ const options = {
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||||
},
|
},
|
||||||
|
compile_cpu_time: {
|
||||||
|
desc: 'Max CPU time allowed for compile stage in milliseconds',
|
||||||
|
default: 10000, // 10 seconds
|
||||||
|
parser: parse_int,
|
||||||
|
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||||
|
},
|
||||||
|
run_cpu_time: {
|
||||||
|
desc: 'Max CPU time allowed for run stage in milliseconds',
|
||||||
|
default: 3000, // 3 seconds
|
||||||
|
parser: parse_int,
|
||||||
|
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||||
|
},
|
||||||
compile_memory_limit: {
|
compile_memory_limit: {
|
||||||
desc: 'Max memory usage for compile stage in bytes (set to -1 for no limit)',
|
desc: 'Max memory usage for compile stage in bytes (set to -1 for no limit)',
|
||||||
default: -1, // no limit
|
default: -1, // no limit
|
||||||
|
@ -117,7 +129,7 @@ const options = {
|
||||||
limit_overrides: {
|
limit_overrides: {
|
||||||
desc: 'Per-language exceptions in JSON format for each of:\
|
desc: 'Per-language exceptions in JSON format for each of:\
|
||||||
max_process_count, max_open_files, max_file_size, compile_memory_limit,\
|
max_process_count, max_open_files, max_file_size, compile_memory_limit,\
|
||||||
run_memory_limit, compile_timeout, run_timeout, output_max_size',
|
run_memory_limit, compile_timeout, run_timeout, compile_cpu_time, run_cpu_time, output_max_size',
|
||||||
default: {},
|
default: {},
|
||||||
parser: parse_overrides,
|
parser: parse_overrides,
|
||||||
validators: [
|
validators: [
|
||||||
|
@ -165,6 +177,8 @@ function parse_overrides(overrides_string) {
|
||||||
'run_memory_limit',
|
'run_memory_limit',
|
||||||
'compile_timeout',
|
'compile_timeout',
|
||||||
'run_timeout',
|
'run_timeout',
|
||||||
|
'compile_cpu_time',
|
||||||
|
'run_cpu_time',
|
||||||
'output_max_size',
|
'output_max_size',
|
||||||
].includes(key)
|
].includes(key)
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -22,7 +22,15 @@ const get_next_box_id = () => ++box_id % MAX_BOX_ID;
|
||||||
|
|
||||||
class Job {
|
class Job {
|
||||||
#dirty_boxes;
|
#dirty_boxes;
|
||||||
constructor({ runtime, files, args, stdin, timeouts, memory_limits }) {
|
constructor({
|
||||||
|
runtime,
|
||||||
|
files,
|
||||||
|
args,
|
||||||
|
stdin,
|
||||||
|
timeouts,
|
||||||
|
cpu_times,
|
||||||
|
memory_limits,
|
||||||
|
}) {
|
||||||
this.uuid = uuidv4();
|
this.uuid = uuidv4();
|
||||||
|
|
||||||
this.logger = logplease.create(`job/${this.uuid}`);
|
this.logger = logplease.create(`job/${this.uuid}`);
|
||||||
|
@ -44,6 +52,7 @@ class Job {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.timeouts = timeouts;
|
this.timeouts = timeouts;
|
||||||
|
this.cpu_times = cpu_times;
|
||||||
this.memory_limits = memory_limits;
|
this.memory_limits = memory_limits;
|
||||||
|
|
||||||
this.state = job_states.READY;
|
this.state = job_states.READY;
|
||||||
|
@ -116,7 +125,15 @@ class Job {
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
async safe_call(box, file, args, timeout, memory_limit, event_bus = null) {
|
async safe_call(
|
||||||
|
box,
|
||||||
|
file,
|
||||||
|
args,
|
||||||
|
timeout,
|
||||||
|
cpu_time,
|
||||||
|
memory_limit,
|
||||||
|
event_bus = null
|
||||||
|
) {
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
let output = '';
|
let output = '';
|
||||||
|
@ -125,7 +142,8 @@ class Job {
|
||||||
let signal = null;
|
let signal = null;
|
||||||
let message = null;
|
let message = null;
|
||||||
let status = null;
|
let status = null;
|
||||||
let time = null;
|
let cpu_time_stat = null;
|
||||||
|
let wall_time_stat = null;
|
||||||
|
|
||||||
const proc = cp.spawn(
|
const proc = cp.spawn(
|
||||||
ISOLATE_PATH,
|
ISOLATE_PATH,
|
||||||
|
@ -143,7 +161,8 @@ class Job {
|
||||||
`--processes=${this.runtime.max_process_count}`,
|
`--processes=${this.runtime.max_process_count}`,
|
||||||
`--open-files=${this.runtime.max_open_files}`,
|
`--open-files=${this.runtime.max_open_files}`,
|
||||||
`--fsize=${Math.floor(this.runtime.max_file_size / 1000)}`,
|
`--fsize=${Math.floor(this.runtime.max_file_size / 1000)}`,
|
||||||
`--time=${timeout / 1000}`,
|
`--wall-time=${timeout / 1000}`,
|
||||||
|
`--time=${cpu_time / 1000}`,
|
||||||
`--extra-time=0`,
|
`--extra-time=0`,
|
||||||
...(memory_limit >= 0
|
...(memory_limit >= 0
|
||||||
? [`--cg-mem=${Math.floor(memory_limit / 1000)}`]
|
? [`--cg-mem=${Math.floor(memory_limit / 1000)}`]
|
||||||
|
@ -292,13 +311,22 @@ class Job {
|
||||||
break;
|
break;
|
||||||
case 'time':
|
case 'time':
|
||||||
try {
|
try {
|
||||||
time = parse_float(value);
|
cpu_time_stat = parse_float(value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to parse cpu time, received value: ${value}`
|
`Failed to parse cpu time, received value: ${value}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'time-wall':
|
||||||
|
try {
|
||||||
|
wall_time_stat = parse_float(value);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to parse wall time, received value: ${value}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +345,8 @@ class Job {
|
||||||
memory,
|
memory,
|
||||||
message,
|
message,
|
||||||
status,
|
status,
|
||||||
time,
|
cpu_time: cpu_time_stat,
|
||||||
|
wall_time: wall_time_stat,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +396,7 @@ class Job {
|
||||||
'/runtime/compile',
|
'/runtime/compile',
|
||||||
code_files.map(x => x.name),
|
code_files.map(x => x.name),
|
||||||
this.timeouts.compile,
|
this.timeouts.compile,
|
||||||
|
this.cpu_times.compile,
|
||||||
this.memory_limits.compile,
|
this.memory_limits.compile,
|
||||||
event_bus
|
event_bus
|
||||||
);
|
);
|
||||||
|
@ -391,6 +421,7 @@ class Job {
|
||||||
'/runtime/run',
|
'/runtime/run',
|
||||||
[code_files[0].name, ...this.args],
|
[code_files[0].name, ...this.args],
|
||||||
this.timeouts.run,
|
this.timeouts.run,
|
||||||
|
this.cpu_times.run,
|
||||||
this.memory_limits.run,
|
this.memory_limits.run,
|
||||||
event_bus
|
event_bus
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Runtime {
|
||||||
pkgdir,
|
pkgdir,
|
||||||
runtime,
|
runtime,
|
||||||
timeouts,
|
timeouts,
|
||||||
|
cpu_times,
|
||||||
memory_limits,
|
memory_limits,
|
||||||
max_process_count,
|
max_process_count,
|
||||||
max_open_files,
|
max_open_files,
|
||||||
|
@ -27,6 +28,7 @@ class Runtime {
|
||||||
this.pkgdir = pkgdir;
|
this.pkgdir = pkgdir;
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
this.timeouts = timeouts;
|
this.timeouts = timeouts;
|
||||||
|
this.cpu_times = cpu_times;
|
||||||
this.memory_limits = memory_limits;
|
this.memory_limits = memory_limits;
|
||||||
this.max_process_count = max_process_count;
|
this.max_process_count = max_process_count;
|
||||||
this.max_open_files = max_open_files;
|
this.max_open_files = max_open_files;
|
||||||
|
@ -62,6 +64,18 @@ class Runtime {
|
||||||
language_limit_overrides
|
language_limit_overrides
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
cpu_times: {
|
||||||
|
compile: this.compute_single_limit(
|
||||||
|
language_name,
|
||||||
|
'compile_cpu_time',
|
||||||
|
language_limit_overrides
|
||||||
|
),
|
||||||
|
run: this.compute_single_limit(
|
||||||
|
language_name,
|
||||||
|
'run_cpu_time',
|
||||||
|
language_limit_overrides
|
||||||
|
),
|
||||||
|
},
|
||||||
memory_limits: {
|
memory_limits: {
|
||||||
compile: this.compute_single_limit(
|
compile: this.compute_single_limit(
|
||||||
language_name,
|
language_name,
|
||||||
|
|
|
@ -178,7 +178,7 @@ default: {}
|
||||||
```
|
```
|
||||||
|
|
||||||
Per-language overrides/exceptions for the each of `max_process_count`, `max_open_files`, `max_file_size`,
|
Per-language overrides/exceptions for the each of `max_process_count`, `max_open_files`, `max_file_size`,
|
||||||
`compile_memory_limit`, `run_memory_limit`, `compile_timeout`, `run_timeout`, `output_max_size`. Defined as follows:
|
`compile_memory_limit`, `run_memory_limit`, `compile_timeout`, `run_timeout`, `compile_cpu_time`, `run_cpu_time`, `output_max_size`. Defined as follows:
|
||||||
|
|
||||||
```
|
```
|
||||||
PISTON_LIMIT_OVERRIDES={"c++":{"max_process_count":128}}
|
PISTON_LIMIT_OVERRIDES={"c++":{"max_process_count":128}}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.10.1",
|
"version": "0.10.1",
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"limit_overrides": {
|
"limit_overrides": {
|
||||||
"compile_timeout": 15000
|
"compile_timeout": 15000,
|
||||||
|
"compile_cpu_time": 15000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"aliases": ["zig"],
|
"aliases": ["zig"],
|
||||||
"limit_overrides": {
|
"limit_overrides": {
|
||||||
"compile_timeout": 15000
|
"compile_timeout": 15000,
|
||||||
|
"compile_cpu_time": 15000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.9.1",
|
"version": "0.9.1",
|
||||||
"aliases": ["zig"],
|
"aliases": ["zig"],
|
||||||
"limit_overrides": {
|
"limit_overrides": {
|
||||||
"compile_timeout": 15000
|
"compile_timeout": 15000,
|
||||||
|
"compile_cpu_time": 15000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue