-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Optimize with thread loader and terser #27014
Conversation
…mize-with-thread-loader
Pinging @elastic/kibana-operations |
💚 Build Succeeded |
…d also for the optimizer workers.
This comment has been minimized.
This comment has been minimized.
💚 Build Succeeded |
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.
LGTM, seems to work great, but I do think we should apply a max to the process count.
💚 Build Succeeded |
This is great, and I am very much looking forward to this change. However, before we merge we need to understand the total memory overhead of an optimize process in production. While we don't provide memory requirements, there are a lot of users with 2GB instances which expect Kibana to optimize within. Understanding what the changes here does to effect those will help us understand how we go forward including if we need to further reduce the max threads due to per-thread overhead. |
…use the same calculated number of cpus to use on parallel tasks on thread loader pool config for terser parallel. refact(NA): lower down the poolTimeout on non dev mode. refact(NA): change devOnlyModules to nonDistributableOnlyModules on warmupThreadLoader config.
@tylersmalley I just ran some tests over 2 digital ocean droplets one of them without the thread-loader worker present on this PR and another one having this work. Both instances were also merged with the branch containing the work for this PR #27259 in order to be able to run and create production bundles from source. Dropplets Hardware:
|
💚 Build Succeeded |
This is very exciting @mistic, and thanks for benchmarking - I also did a quick test on a 2GB VM an see ~200MB less memory overhead when optimizing (down from 1.2GB). 🎉 |
Woah, I'm kinda shocked by that result. More processes takes up less memory... wouldn't have guessed! |
3025f1d
to
1e8538f
Compare
I wonder if the memory improvement came from improvements done in Terser - UglifyJS was historically bad with memory management. |
Yeah I agree with you @tylersmalley and just remember that |
This comment has been minimized.
This comment has been minimized.
💚 Build Succeeded |
* multi thread expensive loaders * revert styles * feat(NA): added thread-loader and cache-loader to base optimizer and dll compiler. * feat(NA): added cache-loader and thread-loader to the optimizer and dll compiler. * feat(NA): use new terser plugin instead of old unmaintained uglifyjs webpack plugin. * refact(NA): remove unused configs from base optimizer and dll compiler. * fix(NA): available cpu calculated number. * docs(NA): fix comment about what we are doing in prod on base_optimizer config. * docs(NA): explain why we are setting memory into each thread loader worker. * fix(NA): add dev only loaders to the thread-loader warmup config. * refact(NA): change name from babelCacheDir to babelLoaderCacheDir. * fix(NA): logic for calculating available cpus. * feat(NA): pass NODE_OPTIONS along for the optimizer forked process and also for the optimizer workers. * feat(NA): remove terser webpack plugin compression from base_optimizer and only run it on dll compiler. * chore(NA): update function to calculate available cpus for works. * fix(NA): apply upperbound to the number of workers we can have on thread-loader. * fix(NA): decrease the max number of thread pool workers. refact(NA): use the same calculated number of cpus to use on parallel tasks on thread loader pool config for terser parallel. refact(NA): lower down the poolTimeout on non dev mode. refact(NA): change devOnlyModules to nonDistributableOnlyModules on warmupThreadLoader config. * chore(NA): update yarn lock deps after merging with master.
* multi thread expensive loaders * revert styles * feat(NA): added thread-loader and cache-loader to base optimizer and dll compiler. * feat(NA): added cache-loader and thread-loader to the optimizer and dll compiler. * feat(NA): use new terser plugin instead of old unmaintained uglifyjs webpack plugin. * refact(NA): remove unused configs from base optimizer and dll compiler. * fix(NA): available cpu calculated number. * docs(NA): fix comment about what we are doing in prod on base_optimizer config. * docs(NA): explain why we are setting memory into each thread loader worker. * fix(NA): add dev only loaders to the thread-loader warmup config. * refact(NA): change name from babelCacheDir to babelLoaderCacheDir. * fix(NA): logic for calculating available cpus. * feat(NA): pass NODE_OPTIONS along for the optimizer forked process and also for the optimizer workers. * feat(NA): remove terser webpack plugin compression from base_optimizer and only run it on dll compiler. * chore(NA): update function to calculate available cpus for works. * fix(NA): apply upperbound to the number of workers we can have on thread-loader. * fix(NA): decrease the max number of thread pool workers. refact(NA): use the same calculated number of cpus to use on parallel tasks on thread loader pool config for terser parallel. refact(NA): lower down the poolTimeout on non dev mode. refact(NA): change devOnlyModules to nonDistributableOnlyModules on warmupThreadLoader config. * chore(NA): update yarn lock deps after merging with master.
6.x: d53a9a2 |
This PR is the result of revisiting an idea explored on #20749 with HappyPack (at that time the results were not good) in the very start of the DLL work experiments and also tried by @jbudz on #21994.
However this changes implements and explores things that we didn't tried before and that are giving us a lot of benefits.
Changes:
thread-loader
to the basic optimizer both forbabel-loader
andts-loader
and also adding it to thebabel-loader
into thedll compiler
cache-loader
for thebabel-loader
into thedll compiler
thread-loader pool
warming it up into thebase optimizer
constructor and sharing it also with thedll compiler
uglifyJsPlugin
withterser-webpack-plugin
as the later is the one used and supported right now bywebpack
since version4.26.0
.compress
fromterser-webpack-plugin
into thebase_optimizer
. We have already done this in the past but were only keeping it due to the dead-code the removal check in React DevTools. So we can keep doing it, but only for theDynamicDllCompiler
.Results:
The results are from a machine with processing power for
8 threads
however I guess it should be closer for machines with a processing power of 2 or more threads.dev
(or running from source)Overall I just felt like the benefits are awesome!