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

ResourceManager: Adjust inbound connection limits depending on memory. #9593

Merged
merged 3 commits into from
Jan 30, 2023

Conversation

ajnavarro
Copy link
Member

@ajnavarro ajnavarro commented Jan 27, 2023

This is in response to libp2p/go-libp2p#2010 for simplification I think we want to be able to do this for Kubo.

I believe will allow the resource manager to get out of the way more but still protect against script-kiddies opening many connections/streams against a node.

In order for this work, established (non-transient) connections will need to register memory usage with the resource manager/accountant, ideally across all transports and muxers. Per libp2p/go-libp2p#2010 (comment), there are some cases where an established libp2p connection doesn't increase memory accounted for by the resource manager/accountant. In the meantime, we can set System.ConssInbound based on ResourceMgr.MaxMemory and then strip this out when libp2p/go-libp2p#2010 lands.

Change tested checking that we do not OOM after a stream flooding attack. Everything working as expected.

Updated defaults values to use totalMemory/2

It closes #9602

@galargh
Copy link
Contributor

galargh commented Jan 27, 2023

Just checking in, any chance we're landing this today for the v0.18.1 release?

@ajnavarro
Copy link
Member Author

@galargh I hope to land it today.

Copy link
Contributor

@BigLep BigLep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. Logic is good. Thanks!

core/node/libp2p/rcmgr_defaults.go Outdated Show resolved Hide resolved
core/node/libp2p/rcmgr_defaults.go Show resolved Hide resolved
docs/libp2p-resource-management.md Outdated Show resolved Hide resolved
docs/libp2p-resource-management.md Outdated Show resolved Hide resolved
docs/libp2p-resource-management.md Outdated Show resolved Hide resolved
docs/changelogs/v0.18.md Outdated Show resolved Hide resolved
docs/changelogs/v0.18.md Outdated Show resolved Hide resolved
core/node/libp2p/rcmgr_defaults.go Outdated Show resolved Hide resolved
@@ -1843,7 +1843,7 @@ This value is also used to scale the limit on various resources at various scope
when the default limits (discussed in [libp2p resource management](./libp2p-resource-management.md)) are used.
For example, increasing this value will increase the default limit for incoming connections.

Default: `[TOTAL_SYSTEM_MEMORY]/4`
Default: `[TOTAL_SYSTEM_MEMORY]/2`
Copy link
Member

@lidel lidel Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 (not familiar with prior discussions, someone else needs to review, but adding comment in favor of this change)

👍 I know @2color run into issues when he was running on a box that had 2 GB RAM on https://fly.io/ box, and his libp2p stack only got 1/4 (512MB).

This should improve default behavior in such setups (allocating 1GB).

@ajnavarro ajnavarro merged commit 3fb644a into master Jan 30, 2023
@ajnavarro ajnavarro deleted the fix/rm-use-memory-for-limits branch January 30, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Resource Manager: Default limits only limit the max memory and FDs and set everything else to unlimited.
4 participants