Memory leak under high bitswap load #8797
Labels
kind/bug
A bug in existing code (including security flaws)
need/triage
Needs initial labeling and prioritization
Checklist
Installation method
built from source
Version
Config
N/A
Description
Bitswap is a big memory hog when you start having 10k+ wantlists.
I belive this is because it use amap
for things like the wantlist, ...This is sad because due to the way we use the maps there, we quickly reach a high level of fragmentation and the buckets wont get freed, taking lots of space for nothing.Linked: golang/go#20135
Edit: I don't know how I missed that, but if I understand correctly go-bitswap creates a copy of the wantlist per partner (the map shrinking stuff might still be there, but have far less of an impact than I first thought (likely the same small impact I mesure in synthetic tests)).
10MiB times 600 easly explains such memory usage.
Profile done with ~50k blocks in the wantlist.
Profile: https://jorropo.net/ipfs/Qmf5J2dyvpBgc6RoKDUTaSzgsSVYqdCJFnFgb5puFRoXEY/profile.zip
FYI a synthetically created wantlist, need tens to hundred millions of elements to reach thoses sizes.
Reproduce
In go-ipfs
Spam the gateway with lots of different files to download concurrently
Everything is in the name, just find a way to request many blocks
Use the #8795 branch
Right now (d086aef) it doesn't rate limit, so you can
ipfs dag stat -s=false Qmfoo
whereQmfoo
is any big dag (tens of gigs in my experience).Tip, use
watch ipfs stats bitswap
to ensure your wantlist don't go past 100k, you likely don't have enough ram for that.Solutions
From time to time, make a new map and copy the data from the old one into the new one.Use a custom map implementation that aggressively chunkThe text was updated successfully, but these errors were encountered: