Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

fix(uglify/index): don't use a worker farm unless more than one process is available #280

Merged

Conversation

hedgepigdaniel
Copy link
Contributor

This should save some memory due to sharing common data within one process instead of spawning a second one.

@jsf-clabot
Copy link

jsf-clabot commented Apr 26, 2018

CLA assistant check
All committers have signed the CLA.

@alexander-akait
Copy link
Member

@hedgepigdaniel Looks like it is save memory only for one core system (one thread), right?

@hedgepigdaniel
Copy link
Contributor Author

hedgepigdaniel commented Apr 27, 2018

The difference is for a two core system - since the default number of workers is numcpus - 1. In our case we have parallel: true in the config, and this causes our two core build server to run two processes even though only one of them is actually doing the minifying.

Tbh, I haven't tested that is uses less memory but I assume that there is at least some memory that is shared in one process that needs to be duplicated in a second one. I tested that it works though 👍

@alexander-akait
Copy link
Member

@hedgepigdaniel Looks you are right today, i am testing memory usage and i think we can merge this 👍

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you additionally try with os.cpus().length instead of os.cpus().length - 1 and see if this works ?

@michael-ciniawsky michael-ciniawsky changed the title Don't use a worker farm unless more than one process is required fix(uglify): don't use a worker farm unless more than one process is available May 5, 2018
@michael-ciniawsky michael-ciniawsky added this to the 1.2.5 milestone May 5, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix(uglify): don't use a worker farm unless more than one process is available fix(uglify/index): don't use a worker farm unless more than one process is available May 5, 2018
@alexander-akait
Copy link
Member

alexander-akait commented May 5, 2018

@michael-ciniawsky os.cpus().length:

  1. When we have one core (os.cpus().length === 1) - we create worker, it is wrong (one thread should be left for webpack and no new thread)
  2. When we have two core (os.cpus().length === 2) - we create two worker, it is wrong (one thread should be left for webpack and don't create new thread because we have 1 thread, it is does make sense, only decrease memory/cpu for creating one thread, i.e. no new thread)
  3. When we have four core (os.cpus().length === 4) - we create 4 worker, it is wrong (one thread should be left for webpack and 3 for uglify)

@michael-ciniawsky
Copy link
Member

The worker-farm docs don't state that there must be one core 'freed' for the 'main' process, but maybe you're right, as mentioned worth a try :).

@alexander-akait
Copy link
Member

@michael-ciniawsky it is good practice, If at least one thread completed it is require webpack main thread to create new thread for other file (otherwise we will lose time).

@alexander-akait
Copy link
Member

@michael-ciniawsky Also using os.cpus().length create new problem for one core system (other used in CI system). We create one extra thread on 1 core system and spend extra resources (memory and cpu). It does not make sense to create a new thread on one core system

@michael-ciniawsky
Copy link
Member

@evilebottnawi We don't certainly know for sure if this would be the case or not, I'm not disagreeing but by at least trying we might get proof of the circumstances here

@alexander-akait
Copy link
Member

@michael-ciniawsky why we should create new thread on one core system? It is does not have any sense

@alexander-akait
Copy link
Member

Each creating new thread using more memory and cpu

@alexander-akait
Copy link
Member

@michael-ciniawsky You can justify in detail what you do not agree with PR, or approve PR

@michael-ciniawsky
Copy link
Member

I don't disagree with anything in this PR, but maybe using os.cpus()-length - 1 is unnecessary as mentioned in the review comment and can be removed

@alexander-akait
Copy link
Member

alexander-akait commented May 5, 2018

@michael-ciniawsky What exactly do you disagree? os.cpus().length - 1 is good practice for all multi threading platforms, do you have knowledge about implement multi threading programs or have experience with this, if not it does not make sense to participate in the discussion and slow down solution of the problem. Each program running in multithreading mode has master process and we should always leave one thread for master (creating new threads, send signal for other process, regular work)

@alexander-akait
Copy link
Member

In short:

@joshwiens
Copy link
Member

Agree with @evilebottnawi here. If you don't have one master thread, you end up context switching all over the place and take a huge performance hit and may as well not thread it at all.

Reserving one thread to orchestrate execution has been a generally accepted practice pretty much since we started leveraging the power of multi-core processors.

@alexander-akait
Copy link
Member

@d3viant0ne can we merge this? i don't have administration right here

@alexander-akait alexander-akait merged commit 3f0767b into webpack-contrib:master May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants