Restrict total threads

So machines with a small amount of cores build faster
v1.18.x
Peter Jaszkowiak 8 years ago
parent 7ccfb5cdc0
commit e8caee3c4c

@ -2,7 +2,6 @@
var async = require('async');
var winston = require('winston');
var os = require('os');
var nconf = require('nconf');
var padstart = require('lodash.padstart');
@ -181,7 +180,7 @@ function build(targets, callback) {
async.series([
beforeBuild,
function (next) {
var parallel = os.cpus().length > 1 && !nconf.get('series');
var parallel = !nconf.get('series');
if (parallel) {
winston.info('[build] Building in parallel mode');
} else {

@ -5,6 +5,7 @@ var async = require('async');
var fs = require('fs');
var childProcess = require('child_process');
var os = require('os');
var winston = require('winston');
var less = require('less');
var postcss = require('postcss');
var autoprefixer = require('autoprefixer');
@ -39,6 +40,10 @@ function setupDebugging() {
var children = [];
Minifier.maxThreads = os.cpus().length - 1;
winston.verbose('[minifier] utilizing a maximum of ' + Minifier.maxThreads + ' additional threads');
Minifier.killAll = function () {
children.forEach(function (child) {
child.kill('SIGTERM');
@ -65,13 +70,14 @@ function forkAction(action, callback) {
children.push(proc);
proc.on('message', function (message) {
proc.kill();
removeChild(proc);
if (message.type === 'error') {
proc.kill();
return callback(new Error(message.message));
return callback(message.err);
}
if (message.type === 'end') {
proc.kill();
callback(null, message.result);
}
});
@ -85,10 +91,6 @@ function forkAction(action, callback) {
type: 'action',
action: action,
});
proc.on('close', function () {
removeChild(proc);
});
}
var actions = {};
@ -109,7 +111,7 @@ if (process.env.minifier_child) {
if (err) {
process.send({
type: 'error',
message: err.message,
err: err,
});
return;
}
@ -124,7 +126,7 @@ if (process.env.minifier_child) {
}
function executeAction(action, fork, callback) {
if (fork) {
if (fork && children.length < Minifier.maxThreads) {
forkAction(action, callback);
} else {
if (typeof actions[action.act] !== 'function') {

Loading…
Cancel
Save