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
Reduce bugtool memory usage #17546
Reduce bugtool memory usage #17546
Conversation
s/ethool/ethtool/ Also fix the build for other non-Linux platforms besides macOS. Signed-off-by: Tobias Klauser <tobias@cilium.io>
Avoid reallocations and GC pressure in the loop. Signed-off-by: Tobias Klauser <tobias@cilium.io>
/test |
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.
🚀
There is no need to recompile the constant regexp for each iteration of the loop. Also, hashEncryptionKeys is called in a loop, so move the regexp compilation to a global var to avoid recompiling it. Signed-off-by: Tobias Klauser <tobias@cilium.io>
Instead of open-coding a worker pool use the existing github.com/cilium/workerpool package. Also limit the number of workers to the number of CPUs by default, which should help to reduce excessive memory usage by too many parallel goroutines at the price of potentially slightly slower bugtool report creation. If users want more parallel tasks, the number can be specified using the newly introduces `--parallel-workers` option. Signed-off-by: Tobias Klauser <tobias@cilium.io>
Converting []byte to string can cause allocation due to the fact that strings are immutable in Go. By letting execCommand return []byte instead of string we can avoid some of these allocations, i.e also the allcoation caused by further processing of that return value. Signed-off-by: Tobias Klauser <tobias@cilium.io>
c61ff98
to
e090a65
Compare
When the command output doiesn't need to be postprocessed, the output can be written directly to the file without buffering. This should significantly reduce memory usage. On my test system this reduces total RSS by about one third: Before: $ /usr/bin/time -f 'RSS=%MKB' cilium-bugtool RSS=63168KB After: $ /usr/bin/time -f 'RSS=%MKB' cilium-bugtool RSS=42752KB Signed-off-by: Tobias Klauser <tobias@cilium.io>
e090a65
to
68d1f63
Compare
/test |
Multicluster test is the only one failing. That test is not required and the failure will be fixed by #17549. All other enabled tests passed, marking as |
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.
Amazing, thanks!
See individual commits and #17309 for details.
On my test system this reduces total RSS by about one third:
Before:
After:
Fixes #17309