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

feat: opt-in Swarm.ResourceMgr (go-libp2p v0.18) #8680

Merged
merged 25 commits into from Apr 8, 2022
Merged

Conversation

marten-seemann
Copy link
Member

@marten-seemann marten-seemann commented Jan 15, 2022

Part of #8761

  • go-libp2p v0.18.0 completes the deprecation of ipfs/go-log@v1 and migrates all remaining repos to ipfs/go-log@v2
  • Adds commands and configuration for libp2p Network Resource Manager
    • ipfs swarm limit --help
    • ipfs swarm stats --help
  • Adds config at Swarm.ResourceMgr
    • Swarm.ResourceMgr.Enabled is a flag, disabled by default

Closes #8722
Closes #1482 🧙‍♂️

@guseggert
Copy link
Contributor

Do you have plans to publish metrics when a RM req is rejected due to exceeded scope limits? That would be very useful operationally to help know when to scale gateway fleets.

@marten-seemann
Copy link
Member Author

The resource manager has a tracer integration (see https://github.com/libp2p/go-libp2p-resource-manager/blob/master/trace.go), so it would be possible to hook this up with Prometheus in one way or the other.

@vyzo
Copy link
Contributor

vyzo commented Feb 11, 2022 via email

@lidel
Copy link
Member

lidel commented Feb 21, 2022

"exchange files" → "cat file" interop test always gets stuck after go -> go2: 8.39 MB (125ms)
(was able to reproduce locally with this PRs binary)

Quick way to reproduce/debug is to run specific test with:
export IPFS_GO_EXEC=/path/to/ipfs-binary-from-libp2p-v018-branch/ipfs
npx ipfs-interop -- -t node --grep "go -> go2: 8.39 MB → works
npx ipfs-interop -- -t node --grep "go -> go2: 67.1 MB" → hangs

Given this PR adds resource manager, I guess some limit is hit?

Update: set DEBUG="ipfsd-ctl:daemon*" IPFS_LOGGING="INFO" in env to see go-ipfs daemon logs.

@lidel
Copy link
Member

lidel commented Feb 24, 2022

DEBUG="ipfsd-ctl:daemon*" IPFS_LOGGING="DEBUG"  npx ipfs-interop -- -t node --grep "go -> go2: 67.1 MB"

Revealed connection being dropped by go-libp2p-resource-manager:

2022-02-24T02:49:11.848+0100    DEBUG   rcmgr   go-libp2p-resource-manager@v0.1.3/scope.go:239  blocked memory reservation      {"scope": "peer:12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL", "size": 258126, "priority": 128, "error": "resource limit exceeded"}
2022-02-24T02:49:11.849+0100    DEBUG   dht     net/message_manager.go:303      error reading message   {"error": "stream reset", "retrying": true}
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/swarm.go:336    [12D3KooWKyDk1EymJbcr59vVjJeJUvwe6vdAUKXnRtbNVt63pvow] opening stream to peer [12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL]
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/swarm_dial.go:241       dialing peer    {"from": "12D3KooWKyDk1EymJbcr59vVjJeJUvwe6vdAUKXnRtbNVt63pvow", "to": "12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL"}
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/limiter.go:193  [limiter] adding a dial job through limiter: /ip4/127.0.0.1/tcp/44017
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/limiter.go:161  [limiter] taking FD token: peer: 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL; addr: /ip4/127.0.0.1/tcp/44017; prev consuming: 0
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/limiter.go:167  [limiter] executing dial; peer: 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL; addr: /ip4/127.0.0.1/tcp/44017; FD consuming: 1; waiting: 0
2022-02-24T02:49:11.849+0100    DEBUG   swarm2  go-libp2p-swarm@v0.10.2/swarm_dial.go:386       12D3KooWKyDk1EymJbcr59vVjJeJUvwe6vdAUKXnRtbNVt63pvow swarm dialing 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL /ip4/127.0.0.1/tcp/44017
2022-02-24T02:49:11.849+0100    INFO    bitswap go-bitswap@v0.5.1/bitswap.go:638        Bitswap ReceiveError: stream reset
2022-02-24T02:49:11.849+0100    DEBUG   bitswap_network network/ipfs_impl.go:413        bitswap net handleNewStream from 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL error: stream reset
2022-02-24T02:49:11.849+0100    INFO    bitswap go-bitswap@v0.5.1/bitswap.go:638        Bitswap ReceiveError: stream reset
2022-02-24T02:49:11.849+0100    DEBUG   bitswap_network network/ipfs_impl.go:413        bitswap net handleNewStream from 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL error: stream reset
2022-02-24T02:49:11.849+0100    INFO    connmgr connmgr/connmgr.go:546  tried to remove tag from untracked peer: 12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL
2022-02-24T02:49:11.849+0100    DEBUG   bs:sprmgr       sessionpeermanager/sessionpeermanager.go:98     Bitswap: removed peer from session      {"session": 1, "peer": "12D3KooWReFVRYtypujVVXkvictuB8PyaZnSraLEDvwQPGSDxMaL", "peerCount": 0}

@marten-seemann
Copy link
Member Author

Revealed connection being dropped by go-libp2p-resource-manager

There's no connection being dropped. The resource manager is blocking a memory with prio 128, which is probably a yamux stream window increase: https://github.com/libp2p/go-yamux/blob/cd22a37b789cf6e1fe4f2c2cff6da5df7a49dfac/stream.go#L229. This won't cause any problems.

Do we have logs from the other node?

@lidel
Copy link
Member

lidel commented Feb 24, 2022

These logs ipfsd-ctl:daemon are from both ends, which make it difficult to debug.

I decided to remove ipfs-interop from the picture and was still able to replicate the issue without it, using two nodes on same machine.

👉 ipfs cat of 65MB file gets stuck

With this setup you can tweak IPFS_LOGGING level for each node independently, and see logs on each end:

Node A (source)

One terminal:

$ export IPFS_PATH=/tmp/node-a
$ ipfs daemon --init --init-profile server,randomports,test

Second terminal:

$ ipfs id | jq '.Addresses[0]' 
{addrA}
$ ipfs swarm connect  {addrB}
$ head -c 65M /dev/urandom | ipfs add -Q
{cid-OK}
$ head -c 8M /dev/urandom | ipfs add -Q
{cid-FAIL}

Node B (destination)

One terminal:

$ export IPFS_PATH=/tmp/node-b
$ ipfs daemon --init --init-profile server,randomports,test

Second terminal:

$ ipfs id | jq '.Addresses[0]' 
{addrB}
$ ipfs swarm connect  {addrA}
$ ipfs cat {cid-OK} > /tmp/8M # finished instantly
$ ipfs cat {cid-FAIL} > /tmp/65M # stops in the middle (around 20-50%)
30.50 MiB / 65.00 MiB [==================================>--------------------------------------]  46.92%

@aschmahmann
Copy link
Contributor

@marten-seemann @lidel I'm not totally sure, but am wondering if we're running into a combination of go-bitswap not gracefully handling the lack of streams and go-bitswap using more streams than it should (ipfs/boxo#80).

@vyzo
Copy link
Contributor

vyzo commented Feb 24, 2022 via email

@marten-seemann marten-seemann force-pushed the update-libp2p-v018 branch 2 times, most recently from 6ddf5bf to 0c9ddba Compare February 28, 2022 12:34
@BigLep BigLep mentioned this pull request Mar 1, 2022
69 tasks
@BigLep BigLep added this to the go-ipfs 0.13 milestone Mar 3, 2022
@BigLep
Copy link
Contributor

BigLep commented Mar 3, 2022

2022-03-03 conversation:

  1. @BigLep : create issue for the overall user story to link to
  2. Making config changes without recompiling will likely be key here, even for the initial gateway testing for validating go-libp2p 0.18.

core/node/libp2p/rcmgr.go Outdated Show resolved Hide resolved
marten-seemann and others added 5 commits April 6, 2022 00:51
* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>
This includes CI fix for go-ipfs-http-client
This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.
Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.
@lidel
Copy link
Member

lidel commented Apr 6, 2022

Applied changes based on feedback from stewards sync:

  • core/node/libp2p/rcmgr_defaults.go vendors all implicit default limits from go-libp2p
  • Ended up keeping limit.json parser and hiding Swarm.ResourceMgr.Limits for now.
    • The way defaults are handled and initialized by go-libp2p is bit complex, there are at least two layers of indirection using different structs.
    • Coming up with Swarm.ResourceMgr.Limits that acts as persistence for ipfs swarm limit -s and is compatible with limit.json will improve UX, but that is additional work which should not block go-libp2p 0.18 from being merged.

Before this is merged, we should make a decision if we are ok with

@lidel lidel changed the title feat: Swarm.ResourceMgr (go-libp2p v0.18) feat: opt-in Swarm.ResourceMgr (go-libp2p v0.18) Apr 7, 2022
@BigLep BigLep requested a review from guseggert April 7, 2022 16:08
core/commands/config.go Outdated Show resolved Hide resolved
core/commands/swarm.go Show resolved Hide resolved
core/node/libp2p/rcmgr_metrics.go Show resolved Hide resolved
core/node/libp2p/rcmgr.go Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@lidel lidel mentioned this pull request Apr 7, 2022
4 tasks
@guseggert guseggert merged commit 514411b into master Apr 8, 2022
@guseggert guseggert deleted the update-libp2p-v018 branch April 8, 2022 01:06
@lidel lidel mentioned this pull request May 31, 2022
3 tasks
@BigLep BigLep mentioned this pull request Jul 26, 2022
68 tasks
hannahhoward pushed a commit to filecoin-project/kubo-api-client that referenced this pull request Jun 19, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
gammazero pushed a commit to ipfs/boxo that referenced this pull request Sep 28, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>

This commit was moved from ipfs/kubo@514411b
gammazero pushed a commit to ipfs/boxo that referenced this pull request Oct 13, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>

This commit was moved from ipfs/kubo@514411b
gammazero pushed a commit to ipfs/boxo that referenced this pull request Oct 13, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>

This commit was moved from ipfs/kubo@514411b
Jorropo pushed a commit to ipfs/boxo that referenced this pull request Oct 24, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>

This commit was moved from ipfs/kubo@514411b
Jorropo pushed a commit to ipfs/boxo that referenced this pull request Oct 24, 2023
* update go-libp2p to v0.18.0

* initialize the resource manager

* add resource manager stats/limit commands

* load limit file when building resource manager

* log absent limit file

* write rcmgr to file when IPFS_DEBUG_RCMGR is set

* fix: mark swarm limit|stats as experimental

* feat(cfg): opt-in Swarm.ResourceMgr

This ensures we can safely test the resource manager without impacting
default behavior.

- Resource manager is disabled by default
    - Default for Swarm.ResourceMgr.Enabled is false for now
- Swarm.ResourceMgr.Limits allows user to tweak limits per specific
  scope in a way that is persisted across restarts
- 'ipfs swarm limit system' outputs human-readable json
- 'ipfs swarm limit system new-limits.json' sets new runtime limits
  (but does not change Swarm.ResourceMgr.Limits in the config)

Conventions to make libp2p devs life easier:
- 'IPFS_RCMGR=1 ipfs daemon' overrides the config and enables resource manager
- 'limit.json' overrides implicit defaults from libp2p (if present)

* docs(config): small tweaks

* fix: skip libp2p.ResourceManager if disabled

This ensures 'ipfs swarm limit|stats' work only when enabled.

* fix: use NullResourceManager when disabled

This reverts commit b19f7c9eca4cee4187f8cba3389dc2c930258512.
after clarification feedback from
ipfs/kubo#8680 (comment)

* style: rename IPFS_RCMGR to LIBP2P_RCMGR

preexisting libp2p toggles use LIBP2P_ prefix

* test: Swarm.ResourceMgr

* fix: location of opt-in limit.json and rcmgr.json.gz

Places these files inside of IPFS_PATH

* Update docs/config.md

* feat: expose rcmgr metrics when enabled (#8785)

* add metrics for the resource manager
* export protocol and service name in Prometheus metrics
* fix: expose rcmgr metrics only when enabled

Co-authored-by: Marcin Rataj <lidel@lidel.org>

* refactor: rcmgr_metrics.go

* refactor: rcmgr_defaults.go

This file defines implicit limit defaults used when Swarm.ResourceMgr.Enabled

We keep vendored copy to ensure go-ipfs is not impacted when go-libp2p
decides to change defaults in any of the future releases.

* refactor: adjustedDefaultLimits

Cleans up the way we initialize defaults and adds a fix for case
when connection manager runs with high limits.

It also hides `Swarm.ResourceMgr.Limits` until we have a better
understanding what syntax makes sense.

* chore: cleanup after a review

* fix: restore go-ipld-prime v0.14.2

* fix: restore go-ds-flatfs v0.5.1

Co-authored-by: Lucas Molas <schomatis@gmail.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>

This commit was moved from ipfs/kubo@514411b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
7 participants