Skip to content

Commit

Permalink
feat(global-options): Default concurrency to logical CPU count (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romms authored and evocateur committed Feb 14, 2019
1 parent a6733a2 commit 2c487fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/command/__tests__/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const tempy = require("tempy");

// partially mocked
const ChildProcessUtilities = require("@lerna/child-process");
const os = require("os");

// normalize concurrency across different environments (localhost, CI, etc)
jest.spyOn(os, "cpus").mockImplementation(() => new Array(42));

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
Expand Down Expand Up @@ -70,14 +74,14 @@ describe("core-command", () => {
const command = testFactory({ concurrency: "bla" });
await command;

expect(command.concurrency).toBe(4);
expect(command.concurrency).toBe(42);
});

it("should fall back to default if concurrency given is 0", async () => {
const command = testFactory({ concurrency: 0 });
await command;

expect(command.concurrency).toBe(4);
expect(command.concurrency).toBe(42);
});

it("should fall back to 1 if concurrency given is smaller than 1", async () => {
Expand Down
3 changes: 2 additions & 1 deletion core/command/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const _ = require("lodash");
const dedent = require("dedent");
const execa = require("execa");
const log = require("npmlog");
const os = require("os");

const PackageGraph = require("@lerna/package-graph");
const Project = require("@lerna/project");
Expand All @@ -14,7 +15,7 @@ const cleanStack = require("./lib/clean-stack");
const logPackageError = require("./lib/log-package-error");
const warnIfHanging = require("./lib/warn-if-hanging");

const DEFAULT_CONCURRENCY = 4;
const DEFAULT_CONCURRENCY = os.cpus().length;

class Command {
constructor(argv) {
Expand Down
2 changes: 1 addition & 1 deletion core/global-options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### `--concurrency`

How many threads to use when Lerna parallelizes the tasks (defaults to `4`)
How many threads to use when Lerna parallelizes the tasks (defaults to count of logical CPU cores)

```sh
$ lerna publish --concurrency 1
Expand Down
4 changes: 3 additions & 1 deletion core/global-options/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const os = require("os");

module.exports = globalOptions;

function globalOptions(yargs) {
Expand All @@ -11,7 +13,7 @@ function globalOptions(yargs) {
type: "string",
},
concurrency: {
defaultDescription: "4",
defaultDescription: os.cpus().length,
describe: "How many processes to use when lerna parallelizes tasks.",
type: "number",
requiresArg: true,
Expand Down

0 comments on commit 2c487fe

Please sign in to comment.