-
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
[Fleet] Cache call to getBundledPackages #172640
[Fleet] Cache call to getBundledPackages #172640
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
d0e950a
to
50e617d
Compare
I think this is a good path forward, and I'd be happy to see the remaining tests fixed. Do you have any concerns with this approach based on what we've been discussing in Slack? |
This will add a little memory overhead, but for bundled packages, I think we maybe able to do something a little smarter by changing the BundledPackage to something like this interface BundledPackage
{
pkgName: string,
pkgVersion: string,
buffer: async () => Buffer // Change here to read buffer only when we need it,
} What do you think? the only part that will be store in memory will the pkgName, version and the buffer will only be retrieved when needed |
Yeah that change to bundled package objects makes sense to me. |
Pinging @elastic/fleet (Team:Fleet) |
@elasticmachine merge upstream |
Pinging @elastic/apm-ui (Team:APM) |
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 🚀
@kpollich do you think we should backport this one? I think we should |
Yes let's backport this - it will fix a substantial memory issue with Fleet so worth the backport. |
@elasticmachine merge upstream |
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
const { pkgName, pkgVersion } = splitPkgKey(zipFile.replace(/\.zip$/, '')); | ||
|
||
const getBuffer = () => fs.readFile(path.join(bundledPackageLocation, zipFile)); |
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.
drive-by comment: maybe this could be wrapped in once()
? Behaviour should be similar as before (this change), but no risk in reading from disk multiple times if the function is called multiple times for whatever reason as well.
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.
@dgieselaar with the once
this will cache the file in memory forever right? it's probably something we want to avoid, we are trying to reduce the fleet memory footprint in kibana too.
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.
what we try to achieve with that PR is to avoid to load all the bundled package in memory when we call getBundledPackage
(that is called in a lot of place in fleet code)
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.
with the once this will cache the file in memory forever right?
No, only in the scope of this call togetBundledPackages
. Which would be the same as before. Wrapping this inonce
simply means that if downstreamgetBuffer
is called twice, it is only read from disk once. Previously it was also read from disk once - this change introduces the possibility that it is read from disk multiple times for eachgetBundledPackages
call.
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.
@dgieselaar that PR changed the getBundledPackages
to cache the results, so those bundled package object we are returning are now global, I made a change in d2c575e to make a copy for each getBundledPackages
and use a once
there does it make sense to you?
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.
ah, yes, makes sense!
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
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @nchaulet |
(cherry picked from commit 2c0e988)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
# Backport This will backport the following commits from `main` to `8.12`: - [[Fleet] Cache call to getBundledPackages (#172640)](#172640) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Nicolas Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-08T17:06:06Z","message":"[Fleet] Cache call to getBundledPackages (#172640)","sha":"2c0e98818729fe5988e17ba53c5e4752f3364039","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:APM","release_note:skip","Team:Fleet","backport:prev-minor","Team:obs-ux-infra_services","apm:review","v8.13.0"],"number":172640,"url":"https://github.com/elastic/kibana/pull/172640","mergeCommit":{"message":"[Fleet] Cache call to getBundledPackages (#172640)","sha":"2c0e98818729fe5988e17ba53c5e4752f3364039"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172640","number":172640,"mergeCommit":{"message":"[Fleet] Cache call to getBundledPackages (#172640)","sha":"2c0e98818729fe5988e17ba53c5e4752f3364039"}}]}] BACKPORT--> Co-authored-by: Nicolas Chaulet <[email protected]>
Summary
getBundledPackages
read all the bundled package from disk every time it's called, if that function is called concurrently it will lead to OOM errors, as reading all packages is quite memory consuming.That draft PR propose a simple in memory cache implementation, and open the discussion on how we can fix/improve that.
I tested this locally with a
--max_old_space_size=717
and there is no OOM memory anymore. @kpollich if it's the way we want to go I can fix the remaining testsI also changed the interface of BundledPackage to lazily get the buffer only when we need.