Skip to content
This repository has been archived by the owner on May 1, 2022. It is now read-only.

Commit

Permalink
#32: Limit number of cores for default --workers
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel van Uden committed Jul 29, 2015
1 parent a1be9ef commit 7b20186
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Use the applicable instructions for the interface of your choice (currently limi
The [command-line interface](http://en.wikipedia.org/wiki/Command-line_interface) does not have a graphical component and is ideal for automation purposes and headless machines. The interface can run using a sequence of series addresses (the site address containing the chapter listing), or with a batch-mode source file. The `mangarack --help` command will produce the following output:

Usage: mangarack [options]

Options:

-h, --help output usage information
-V, --version output the version number
-a, --animation Disable image animation framing.
Expand Down Expand Up @@ -120,7 +120,7 @@ Download *Aoi Hana* from *MangaFox* and *Citrus* from *Batoto* to the current wo
* `-o <s> or --output <s>` sets the output directory (defaults to *current work directory*).
* `-s <s> or --source <s>` sets the batch-mode source file (defaults to *MangaRack.txt*)
* `-t <s> or --transform <s>` sets an overriding image format transformation (e.g. *jpg*).
* `-w <s> or --workers <s>` sets the maximum concurrency (defaults to the machines cores).
* `-w <s> or --workers <s>` sets the maximum concurrency (defaults to # of cores, up to 4).

## Developers

Expand Down
12 changes: 11 additions & 1 deletion lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var parse = require('./parse');
var options = parse(process.argv);
_initialize(options, options.source || defaultSource, function(err, tasks) {
if (err) return console.error(err.stack || err);
var maximum = options.workers || os.cpus().length;
var maximum = options.workers || _getNumberOfCores();
nodejs(tasks, maximum).on('data', function(data) {
console.log(_pretty(data));
}).on('error', function(err) {
Expand All @@ -38,6 +38,16 @@ function _calculate(timeInMs) {
return '(' + hours + ':' + minutes + ':' + seconds + ')';
}

/**
* Gets the number of cores, limited to a maximum of 4.
* @returns {number}
*/
function _getNumberOfCores() {
var numberOfCores = os.cpus().length;
if (numberOfCores > 4) return 4;
return numberOfCores;
}

/**
* Initializes the tasks.
* @private
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"name": "mangarack",
"repository": "git://github.com/Deathspike/mangarack.js.git",
"version": "3.1.6",
"version": "3.1.7",
"bin": {
"mangarack": "./bin/mangarack"
},
Expand Down

0 comments on commit 7b20186

Please sign in to comment.