mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
Improved memory limits (#248)
* Added optional compile_memory_limit and run_memory_limit parameters * Combined memory limit parameters into one
This commit is contained in:
parent
eaf0ba34bd
commit
fb102ebe83
4 changed files with 65 additions and 6 deletions
|
@ -19,7 +19,7 @@ let gid = 0;
|
|||
|
||||
class Job {
|
||||
|
||||
constructor({ runtime, files, args, stdin, timeouts }) {
|
||||
constructor({ runtime, files, args, stdin, timeouts, memory_limits }) {
|
||||
this.uuid = uuidv4();
|
||||
this.runtime = runtime;
|
||||
this.files = files.map((file,i) => ({
|
||||
|
@ -30,6 +30,7 @@ class Job {
|
|||
this.args = args;
|
||||
this.stdin = stdin;
|
||||
this.timeouts = timeouts;
|
||||
this.memory_limits = memory_limits;
|
||||
|
||||
this.uid = config.runner_uid_min + uid;
|
||||
this.gid = config.runner_gid_min + gid;
|
||||
|
@ -67,7 +68,7 @@ class Job {
|
|||
logger.debug('Primed job');
|
||||
}
|
||||
|
||||
async safe_call(file, args, timeout) {
|
||||
async safe_call(file, args, timeout, memory_limit) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const nonetwork = config.disable_networking ? ['nosocket'] : [];
|
||||
|
||||
|
@ -78,6 +79,10 @@ class Job {
|
|||
'--fsize=' + config.max_file_size
|
||||
];
|
||||
|
||||
if (memory_limit >= 0) {
|
||||
prlimit.push('--as=' + memory_limit);
|
||||
}
|
||||
|
||||
const proc_call = [
|
||||
...prlimit,
|
||||
...nonetwork,
|
||||
|
@ -161,7 +166,8 @@ class Job {
|
|||
compile = await this.safe_call(
|
||||
path.join(this.runtime.pkgdir, 'compile'),
|
||||
this.files.map(x => x.name),
|
||||
this.timeouts.compile
|
||||
this.timeouts.compile,
|
||||
this.memory_limits.compile
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -170,7 +176,8 @@ class Job {
|
|||
const run = await this.safe_call(
|
||||
path.join(this.runtime.pkgdir, 'run'),
|
||||
[this.files[0].name, ...this.args],
|
||||
this.timeouts.run
|
||||
this.timeouts.run,
|
||||
this.memory_limits.run
|
||||
);
|
||||
|
||||
this.state = job_states.EXECUTED;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue