[dev/server] improve startup time and prevent OOMs on shutdown #78710
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
returned to draft
I'm hoping that #79052 + #79235 #79358 will make this unnecessary.
In development the kibana CLI morphs into a different tool that is designed to be helpful when working on Kibana. It's current responsibilities include:
@kbn/optimizerin the same process, which launches webpack workers in child processesThese responsibilities are managed by the
ClusterManagerclass, except for the proxy server which is managed by the core so that the HTTP interface mimics the Kibana server as closely as possible even while all requests are actually being proxied.Over the process of migrating to the KP and deprecating the legacy process the amount of work happening in the parent process has grown substantially and lead to a serious slowdown of the server. Additionally, since we use
@babel/registerand the code base has grown substantially, stopping the dev CLI often triggers an OOM unless you set theNODE_OPTIONSenvironment variable to increase themax-old-space-sizeof the node process. This is caused by the fact that@babel/registermaintains a cache of all transpiled code, and then synchronously at shutdown will serialize that object to JSON and write it to the file system. The massive amount of code we're asking it to transpile on the fly simply doesn't fit in memory with the defaultmax-old-space-sizeof the Kibana process.In order to improve the dev CLI experience I've made three changes:
NODE_OPTIONSto "--max-old-space-size=4096" in the environment of the Kibana server child processThese changes greatly reduce the memory requirements of the parent process, prevent the babel/register cache from being read or set in the parent process (which saves a surprising amount of time now that we don't need the cache and only load the core platform code), and increase the server processes ability to write the babel/register cache without OOMing.
Here are some stats that I collected on my computer, stats on other machines will surely vary and I'd love to see what you get.
This PR:
master: