Skip to content
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

Memory leak under high bitswap load #8797

Closed
3 tasks done
Jorropo opened this issue Mar 17, 2022 · 3 comments
Closed
3 tasks done

Memory leak under high bitswap load #8797

Jorropo opened this issue Mar 17, 2022 · 3 comments
Labels
kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization

Comments

@Jorropo
Copy link
Contributor

Jorropo commented Mar 17, 2022

Checklist

Installation method

built from source

Version

go-ipfs version: 0.13.0-dev
Repo version: 12
System version: amd64/linux
Golang version: devel go1.19-4e26ab0ed8 Tue Mar 15 17:29:54 2022 +0000

Config

N/A

Description

Bitswap is a big memory hog when you start having 10k+ wantlists.

I belive this is because it use a map 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.

Capture d’écran du 2022-03-17 04-35-00

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 where Qmfoo 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 chunk
  • Refactor the map out (have I talked about rewriting the bitswap client into a workstealing meta / overlay scheduler yet ?)
  • ... ?
@Jorropo Jorropo added kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization labels Mar 17, 2022
@guseggert
Copy link
Contributor

This is a well-known problem with bitswap, we experience this often on the gateways, here is the go-bitswap tracking issue: ipfs/boxo#79

@BigLep
Copy link
Contributor

BigLep commented Mar 17, 2022

@Jorropo : yeah, this definitely needs to get solved. It's on the roadmap to get to "soon". Help is likely going to be needed here, at least on reviewing.

I'm not sure your bitswap knowledge, but maybe consider reviewing the updated spec (which needs review anyways) ipfs/specs#269 to ramp up to be able to help more here?

@BigLep
Copy link
Contributor

BigLep commented Mar 18, 2022

We're going to close and let ipfs/boxo#79 be the master issue.

@BigLep BigLep closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

3 participants