-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Enable multiple jobs for make when build from source #752
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
Conversation
Can you explain a bit more about what's happening in this PR? |
@@ -1043,6 +1043,9 @@ nvm_install_node_source() { | |||
if [ "_$NVM_OS" = "_freebsd" ]; then | |||
make='gmake' | |||
MAKE_CXX="CXX=c++" | |||
MAKE_JOBS="`sysctl hw.ncpu | awk '{print $2}'`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use $()
instead of backticks; same below
If you have multi-core/processor platform, should let them work in parallel to speed up the build, there is no reason to use only one thread to build on multi-core/processor computer. |
Thank you, but i mean, what is What happens now that this is set? Is there any reason a user might not want this setting turned on? |
@ljharb It's use to determinate how many thread(s) should |
So is |
No, we usually set to N + 1, N is fine enough, you can see many and many examples on the Internet. Examples: |
On my Mac, I get Any commands we use must be |
Should work on mac now. |
elif [ "_$NVM_OS" = "_sunos" ]; then | ||
MAKE_JOBS="$(psrinfo | wc -l)" | ||
else | ||
MAKE_JOBS="1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance that any of the other commands could fail, making MAKE_JOBS
be the empty string, and not hitting this else
block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be very special case I think, but if you want, I can modify it to:
if [ "_$NVM_OS" = "_linux" ]; then
MAKE_JOBS="$(nproc)"
elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
MAKE_JOBS="$(sysctl -n hw.ncpu)"
elif [ "_$NVM_OS" = "_sunos" ]; then
MAKE_JOBS="$(psrinfo | wc -l)"
fi
if [ -z "$MAKE_JOBS" ]; then
MAKE_JOBS="1"
fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I think that'd be more reliable. Thanks for being diligent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to add additional info in that part, hope you don't mind.
Looks like |
I think we can assume linux will have |
This is incorrect. I'm running a quad-core odroid-c1 with trusty on it, and /proc/cpuinfo doesn't contain 'core id'. There's probably a few dozen ways of obtaining this information, however the most portable solution of all is likely to be The best way, however, might also be to just allow passing of custom parameters to the build system. |
Sounds like |
hmmmmm ... anyway, we can fallback to 1 if not detect, and there is also warning msg, why not just enable this feature first and improve it in future? Current code should work on most of the systems. |
The concern would be that building on more processors without informing the user might be taking more processor resources than the user actually wants it to take. |
What about adding an option for non-multithreading compiling? |
@PeterDaveHello That could be fine. I'm concerned about the default, though. Perhaps it's OK though if the default is |
Agree! |
@ljharb I just updated this PR, now it support |
@@ -1231,6 +1231,25 @@ nvm_install_node_source() { | |||
make='gmake' | |||
MAKE_CXX="CXX=c++" | |||
fi | |||
|
|||
if [ -z "$NVM_CPU_THREADS" ] || [[ ! $NVM_CPU_THREADS =~ ^[0-9]+$ ]] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this syntax is bash-specific - nvm
must work on all POSIX systems, including ksh, dash, sh, bash, and zsh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh okay, I'll modify it.
@ljharb I'm not sure why this test failed: https://travis-ci.org/creationix/nvm/jobs/98080035, do you mind to point me out? Thanks a lot! |
Failed on the new installation test of sh/dash but didn't see any useful info in the build log... |
You can definitely ignore the |
Yeah, and I can't pass the test I wrote now 😈 trying to fix it |
I just dropped a robustness test of giving non-expected value for |
@ljharb is it good to merge now? |
echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&2 | ||
NVM_MAKE_JOBS="1" | ||
else | ||
NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we output something to stdout here indicating what the number of threads has been automatically set to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course.
When I tried |
Yep I didn't handle out of order input yet, any suggestion on this? |
Updated for output first. |
For the argument ordering: I think you'll want to loop through the arguments, stopping when you get to the first one that's not |
Can we implement that as another feature? Maybe this PR is just for essential support for multiple threads. |
@PeterDaveHello sure, can you rebase once more? that install_script test won't fail anymore |
Okay, rebased. Do you know the problem that cause build failed before? |
@PeterDaveHello yes, travis-ci/travis-ci#5363 is the culprit |
👍 |
Test passed 😄 |
[New] `nvm install`: Enable multiple jobs for make when build from source via `-j`
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1) | ||
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then | ||
NVM_MAKE_JOBS=$1 | ||
echo "Set number of jobs to $MAKE_JOBS for 'make' utility" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this var name is incorrect (i'll fix in a followup)
Followup: f279837 |
👍 |
Should build parallelly to make the whole process faster.