Correctly handle concurrency

pull/20/head
Johannes J. Schmidt 11 years ago
parent 78bcc94b72
commit 76c4788adb

@ -26,12 +26,14 @@ Now CouchDB takes care of the couchmagick process.
; Optional username and password ; Optional username and password
username = mein-user username = mein-user
password = secure password = secure
; Number of simultanous streams. Default is 1 ; Number of simultanous streams. Default is 1.
streams = 8 streams = 8
; Concurrency level (number of simultanous convert processes). Default is 1
concurrency = 8
; Timeout in ms. Default is 10000 ; Timeout in ms. Default is 10000
timeout = 1000 timeout = 1000
; Batch size. Default is 100 ; Batch size. Default is 100
limit = 1000 limit = 10
``` ```
Imagemagick Configuration Imagemagick Configuration

@ -28,18 +28,20 @@ couchmagick.get({
}, },
// Batching // Batching
streams: pkg.name + '.streams', concurrency: pkg.name + '.concurrency',
limit: pkg.name + '.limit', streams: pkg.name + '.streams',
timeout: pkg.name + '.timeout' limit: pkg.name + '.limit',
timeout: pkg.name + '.timeout'
}, function(err, config) { }, function(err, config) {
if (err) { if (err) {
return process.exit(0); return process.exit(0);
} }
// defaults // defaults
config.streams = config.streams || 4; config.concurrency = config.concurrency || 1;
config.timeout = config.timeout || 10000; config.streams = config.streams || 1;
config.limit = config.limit || 100; config.timeout = config.timeout || 10000;
config.limit = config.limit || 100;
couchmagick.info('using config ' + JSON.stringify(config).replace(/"password":".*?"/, '"password":"***"')); couchmagick.info('using config ' + JSON.stringify(config).replace(/"password":".*?"/, '"password":"***"'));
@ -50,14 +52,15 @@ couchmagick.get({
var couch = url.format({ var couch = url.format({
protocol: 'http', protocol: 'http',
hostname: config.address, hostname: config.address,
port: config.port, port: config.port,
auth: config.auth && config.auth.username && config.auth.password ? [ config.auth.username, config.auth.password ].join(':') : null auth: config.auth && config.auth.username && config.auth.password ? [ config.auth.username, config.auth.password ].join(':') : null
}); });
var options = { var options = {
limit: config.limit, limit: config.limit,
feed: 'continuous', feed: 'continuous',
timeout: config.timeout timeout: config.timeout,
concurrency: config.concurrency
}; };
@ -73,6 +76,7 @@ couchmagick.get({
stream.on('end', next); stream.on('end', next);
} }
// main loop ;) // main loop ;)
function run(err) { function run(err) {
if (err) { if (err) {
@ -89,7 +93,7 @@ couchmagick.get({
return process.exit(0); return process.exit(0);
} }
async.eachLimit(dbs, config.processes, listen, run); async.eachLimit(dbs, config.streams, listen, run);
}); });
} }
run(); run();

@ -1,6 +1,6 @@
{ {
"name": "couchmagick", "name": "couchmagick",
"version": "1.5.2", "version": "1.6.0",
"description": "Run ImageMagicks `convert` on CouchDB documents.", "description": "Run ImageMagicks `convert` on CouchDB documents.",
"main": "index.js", "main": "index.js",
"preferGlobal": true, "preferGlobal": true,
@ -29,7 +29,7 @@
"dependencies": { "dependencies": {
"async": "~0.2.9", "async": "~0.2.9",
"event-stream": "~3.0.20", "event-stream": "~3.0.20",
"couchmagick-listen": "~1.4.3", "couchmagick-listen": "~1.5.0",
"couch-daemon": "~1.2.1", "couch-daemon": "~1.2.1",
"nano": "~4.2.1" "nano": "~4.2.1"
}, },

Loading…
Cancel
Save