Add parallel build option and build logging

This commit is contained in:
1computer1 2019-05-20 16:19:41 -04:00
parent b275fd548d
commit 5618aed14b
3 changed files with 27 additions and 11 deletions

View file

@ -121,5 +121,7 @@ The container is locked down, so there is no networking, limited memory and CPU
- `timeout` Time limit for code in milliseconds. - `timeout` Time limit for code in milliseconds.
- `prepare` Whether to start containers on setup. - `prepare` Whether to start containers on setup.
Setting to true will speed up the first eval, but that language might not be used. Setting to true will speed up the first eval, but that language might not be used.
- `parallel` Whether to build images and container in parallel.
Faster, but will take more resources.
- `concurrent` Number of code evaluations per language than can run at a time. - `concurrent` Number of code evaluations per language than can run at a time.
0. Run `node .` 0. Run `node .`

View file

@ -12,5 +12,6 @@
"cpus": "0.25", "cpus": "0.25",
"timeout": 10000, "timeout": 10000,
"prepare": false, "prepare": false,
"parallel": true,
"concurrent": 10 "concurrent": 10
} }

View file

@ -53,17 +53,29 @@ class LanguageHandler extends AkairoHandler {
return this.modules.get(this.aliases.get(alias.toLowerCase())); return this.modules.get(this.aliases.get(alias.toLowerCase()));
} }
buildDocker() { async buildDocker() {
return Promise.all(this.modules.map(({ loads }) => { if (this.client.config.parallel) {
return Promise.all(loads.map(async dockerID => { await Promise.all(this.modules.map(({ loads }) => Promise.all(loads.map(dockerID => this.buildImage(dockerID)))));
return;
}
for (const { loads } of this.modules.values()) {
for (const dockerID of loads) {
// eslint-disable-next-line no-await-in-loop
await this.buildImage(dockerID);
}
}
}
async buildImage(dockerID) {
const folder = path.join(__dirname, '../../docker', dockerID); const folder = path.join(__dirname, '../../docker', dockerID);
await util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${dockerID}" ${folder}`); await util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${dockerID}" ${folder}`);
// eslint-disable-next-line no-console
console.log(`Built image 1computer1/comp_iler:${dockerID}.`);
this.queues.set(dockerID, new Queue(10)); this.queues.set(dockerID, new Queue(10));
if (this.client.config.prepare) { if (this.client.config.prepare) {
await this.setupContainer(dockerID); await this.setupContainer(dockerID);
} }
}));
}));
} }
async setupContainer(dockerID) { async setupContainer(dockerID) {
@ -82,6 +94,7 @@ class LanguageHandler extends AkairoHandler {
try { try {
await this.handleSpawn(proc); await this.handleSpawn(proc);
this.containers.set(dockerID, { name, count: 0 }); this.containers.set(dockerID, { name, count: 0 });
console.log(`Started container ${name} for 1computer1/comp_iler:${dockerID}.`);
return this.containers.get(dockerID); return this.containers.get(dockerID);
} catch (err) { } catch (err) {
throw err; throw err;