diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b551121 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +1. ~~add time format line (https://www.man7.org/linux/man-pages/man1/time.1.html#top_of_page)~~ \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile index ec0d2a8..4436fbc 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -4,8 +4,8 @@ ENV DEBIAN_FRONTEND=noninteractive RUN dpkg-reconfigure -p critical dash RUN for i in $(seq 1001 1500); do \ - groupadd -g $i runner$i && \ - useradd -M runner$i -g $i -u $i ; \ + groupadd -g $i runner$i && \ + useradd -M runner$i -g $i -u $i ; \ done RUN apt-get update && \ apt-get install -y libxml2 gnupg tar coreutils util-linux libc6-dev \ @@ -13,7 +13,7 @@ RUN apt-get update && \ libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps python3 \ libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev \ libfftw3-dev libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev \ - libsundials-dev libpcre2-dev && \ + libsundials-dev libpcre2-dev time && \ rm -rf /var/lib/apt/lists/* RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen diff --git a/api/package.json b/api/package.json index 0b91c01..e9a811a 100644 --- a/api/package.json +++ b/api/package.json @@ -17,4 +17,4 @@ "waitpid": "git+https://github.com/HexF/node-waitpid.git" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/api/src/job.js b/api/src/job.js index a2641f9..cc2d236 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -154,6 +154,13 @@ class Job { Math.ceil(timeout / 1000), ]; + const time_format = [ + '-f', + // https://www.man7.org/linux/man-pages/man1/time.1.html#top_of_page + // elapsed user system memory + '%es %Us %Ss %MKb', + ] + if (memory_limit >= 0) { prlimit.push('--as=' + memory_limit); } @@ -163,6 +170,8 @@ class Job { ...timeout_call, ...prlimit, ...nonetwork, + 'time', + ...time_format, 'bash', file, ...args, @@ -172,6 +181,8 @@ class Job { var stderr = ''; var output = ''; + var start_time = new Date().getTime(); + const proc = cp.spawn(proc_call[0], proc_call.splice(1), { env: { ...this.runtime.env_vars, @@ -265,14 +276,48 @@ class Job { proc.on('close', (code, signal) => { this.close_cleanup(); - resolve({ stdout, stderr, code, signal, output }); + if (stderr.length > 0) { + var stats = stderr.trim().split('\n').slice(-1).join('\n').split(' '); + + stderr = stderr.trim().split('\n').slice(0, -1).join('\n'); + output = output.trim().split('\n').slice(0, -1).join('\n'); + + stats = { + 'elapsed_time': stats[0], + 'cpu_time': stats[1] + ' / ' + stats[2], + 'max_mem': stats[3], + } + } + + var end_time = new Date().getTime(); + var exec_time = end_time - start_time; + + this.logger.debug(`Stats:`, stats); + resolve({ stdout, stderr, code, signal, output, stats, exec_time }); }); proc.on('error', err => { this.exit_cleanup(); this.close_cleanup(); - reject({ error: err, stdout, stderr, output }); + if (stderr.length > 0) { + var stats = stderr.trim().split('\n').slice(-1).join('\n').split(' '); + + stderr = stderr.trim().split('\n').slice(0, -1).join('\n'); + output = output.trim().split('\n').slice(0, -1).join('\n'); + + stats = { + 'elapsed_time': stats[0], + 'cpu_time': stats[1] + ' / ' + stats[2], + 'max_mem': stats[3], + } + } + + var end_time = new Date().getTime(); + var exec_time = end_time - start_time; + + this.logger.debug(`Stats:`, stats); + reject({ error: err, stdout, stderr, output, stats, exec_time }); }); }); } diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 8a0d385..3eb89e9 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -12,13 +12,14 @@ services: volumes: - ./data/piston/packages:/piston/packages environment: - - PISTON_REPO_URL=http://repo:8000/index + - PISTON_REPO_URL=https://github.com/engineer-man/piston/releases/download/pkgs/index tmpfs: - /piston/jobs:exec,uid=1000,gid=1000,mode=711 - repo: # Local testing of packages + repo: + # Local testing of packages build: repo container_name: piston_repo - command: ['--no-build'] # Don't build anything + command: [ '--no-build' ] # Don't build anything volumes: - .:/piston