Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"npm run watch" runs lerna with too many threads #3950

Closed
jmoujaes opened this issue Feb 9, 2018 · 9 comments
Closed

"npm run watch" runs lerna with too many threads #3950

jmoujaes opened this issue Feb 9, 2018 · 9 comments

Comments

@jmoujaes
Copy link
Contributor

jmoujaes commented Feb 9, 2018

Description

Hello! I would like to make a suggestion to reduce the number of threads used by lerna in the "npm run watch" script.

"watch": "lerna run watch --no-sort --stream --concurrency 999"

I suggest using the default number of threads (4) instead of the current number (999). The reason is that my VM froze up when I tried to run "npm run watch".

Environment

Gatsby version: master
Node.js version: v8.9.4
Operating System: Ubuntu 16.04 VM running on a Windows host. Has 4GB of RAM allotted. Had 8 firefox tabs open as well as one terminal session in which I ran the "npm run watch" command.

Actual result

VM froze.

Expected behavior

VM shouldn't freeze.

Steps to reproduce

1. Configure Ubuntu 16.04 VM with 4GB of RAM. Start the VM

2. Open up 8 firefox tabs, browse to github in all of them.

3. Open up one terminal session.

4. Go to your forked gatsby project root.

5. Run "npm run watch"

6. Notice slowness or freezing.

Note

I'm happy to make a PR.
Thanks for reading!

@m-allanson
Copy link
Contributor

Ahh, that's why watch makes my machine chug for a few minutes. Sounds like a good change to me?

@KyleAMathews
Copy link
Contributor

We need a separate watch process for each package — you can't restrict it to 4 as watch processes don't quit. Four would start up and then... the others would never be able to start.

A better solution perhaps would be a way to select which packages to watch as most of the time you're only editing 1 or maybe 2-3 packages.

@jmoujaes
Copy link
Contributor Author

jmoujaes commented Feb 12, 2018

I see. So the reason for the slowdown is that it is watching a lot of packages, not that the concurrency flag is 999.

Something like this may accomplish what you're saying
npm run watch -- --scope={gatsby,gatsby-cli}

That passes --scope={gatsby,gatsby-cli} to the watch script and appends it to the end. So it effectively becomes
lerna run watch --no-sort --stream --concurrency 999 --scope={gatsby,gatsby-cli}
which will only watch changes for those two packages.

A little bit of context around how I came to file the issue is I was going through the steps in contributing.md to try to work another bug. I ran "npm run watch" which made it watch all the packages.

Do you think it would be worthwhile to put a note in there saying that it is a CPU intensive operation and suggest passing the package names individually?

@m-allanson
Copy link
Contributor

@jmoujaes that sounds like a good fix. However I think you'd initially need all the packages built, as some of them depend on each other.

Maybe we need an earlier step in the docs that creates the initial built files. Something like:

  • Run npm run lerna-prepublish to create an initial build of each package
  • Run npm run watch. The watch command can be resource intensive. To limit it to the packages you're working on, add a scope flag, like npm run watch -- --scope={gatsby,gatsby-cli}

@KyleAMathews
Copy link
Contributor

@m-allanson the bootstrap script which you should run to setup the repo does run pre-publish

"bootstrap": "npm-run-all -s check-versions lerna-prepublish",

Didn't know about scope! Yeah, we should add that to the docs — @jmoujaes could you edit the CONTRIBUTING document to change npm run watch to demonstrate how to scope watching to packages you'll be editing?

@KyleAMathews
Copy link
Contributor

@jmoujaes
Copy link
Contributor Author

Created PR, please let me know if you have any suggestions.
#4020

@KyleAMathews
Copy link
Contributor

Thanks @jmoujaes!

@jmoujaes
Copy link
Contributor Author

For sure, thank you both for being responsive!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants