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

Why do we need msgio.pool ? replace msgio with delimited? #301

Closed
y0sher opened this issue Mar 19, 2018 · 1 comment
Closed

Why do we need msgio.pool ? replace msgio with delimited? #301

y0sher opened this issue Mar 19, 2018 · 1 comment

Comments

@y0sher
Copy link

y0sher commented Mar 19, 2018

https://github.com/google/kythe/blob/master/kythe/go/platform/delimited/delimited.go

Delimited is a file written by google in the kythe project to do prefix length delimited read/write operations.
can you see any better reason to use msgio over that ? I don't really see why pools are important..

@Stebalien
Copy link
Member

So, we need to reuse buffers somehow. If we don't, GC gets very unhappy due to too many short-lived allocations.

delimited does this by reusing a single buffer for each connection. Unfortunately, go-libp2p tends to keep around >500 connections (with a bunch of streams multiplexed on-top) and the messages we send can be up quire large (e.g., 256KiB or even 1MiB). If we had to keep a 256KiB buffer around for each connection, we'd end up wasting a ton of memory.

Instead, msgio reads the length of the next message using a small buffer and then grabs a buffer of the appropriate size from the buffer pool. This way, we don't have to lock-up a large buffer for every idle connection.

marten-seemann added a commit that referenced this issue Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants