-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Badger Allocates A Lot Of Memory When Iterating Over Large Key Value Stores #1326
Comments
@bonedaddy The high memory usage you're seeing comes from Lines 323 to 325 in 9459a24
I would've expected golang GC to take care of the allocations/reclaimation but maybe since we're allocating so many []byte slices, the GC doesn't run that often. I think we can optimize this by having one block buffer per table. That way it will be reused across multiple t.read calls.
Do you see high memory usage when you open file in |
ah makes sense. A reusable buffer would definitely reduce memory a ton.
I tried setting table loading to memory map and kept the value loading to fileio and that increased memory consumption by a lot more. Previously my service was consuming 2.4GB of memory with both value and table loading set to fileio after iterating over all the keys, however when using memory map for table loading, and fileio for value loading memory jumped to 3.5GB |
@bonedaddy You should also set the |
Yep even with that, using mmap for TableLoading consumed the 3.5GB of memory, and both table loading + value loading at fileIO with L0InMemory to false, consumed the 2.4GB |
@bonedaddy can you get a memory profile when the memory usage is high? |
I can capture another one, but I included one when i opened up the issue, ill work on getting another profile though:
|
Here's a capture from badger operating with table and file loading modes at |
Thanks @bonedaddy. I'll look it up and get back. |
Thanks, let me know if I need to capture anymore profiles |
@bonedaddy How big are your values? Also, can you send me the memprofile file? The graph doesn't show the exact line which is consuming the memory. |
Github issues have been deprecated. |
What version of Go are you using (
go version
)?What operating system are you using?
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
What version of Badger are you using?
v2.0.3
Does this issue reproduce with the latest master?
Haven't tried
Steps to Reproduce the issue
What Badger options were set?
Default options with the following modifications:
I've also set the following:
What did you do?
At the start of my service, the key-value store will be iterated over to announce to peers data in the key-value store. Unfortunately however when storing a large amount of data in that key-value store (1.7TB), iterative over the kv allocates a large amount of memory.
What did you expect to see?
Being able to iterate over the keys without allocating a large amount of memory
What did you see instead?
2GB+ of allocations when iterating over all the keys in a large datastore of 1.7TB
Additional Information
I recorded the following profile which shows what's responsible for the memory allocations:
It looks like this is because I have a function that is iterative over all the keys in the key-value store to broadcast the keys to another peer. I'm not sure why this would result in a massive amount of memory being allocated though.
This seems somewhat related to other reported issues such as #1268. The usage of
FileIO
for table and value log loading mode seems to decrease memory usage abit, however it seems like the overall process of reading keys and/org value from badger requires a lot of memoryThe text was updated successfully, but these errors were encountered: