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

Test and document use and performance of Go 1.19's GC memory limit #9327

Closed
3 tasks done
dokterbob opened this issue Oct 5, 2022 · 7 comments
Closed
3 tasks done
Labels
kind/feature A new feature P2 Medium: Good to have, but can wait until someone steps up

Comments

@dokterbob
Copy link
Contributor

Checklist

  • My issue is specific & actionable.
  • I am not suggesting a protocol enhancement.
  • I have searched on the issue tracker for my issue.

Description

In addition to the upcoming Resource Manager, as of version 1.19, Golang has a built-in soft memory limit option, which tunes how the garbage collector operates within memory-constrained environments. This option can be set either using the GOMEMLIMIT environment varibale or by using SetMemoryLimit in the runtime/debug package.

The current default configuration of kubo under high load tends to eat all the memory it can gets until it gets until killed by the OOM, causing frequent restarts of nodes and loss of connections and service.

The new resource manager should be able to address some of these issues. However, documenting and testing Go's native soft memory limits could still significantly improve performance and/or memory usage, particularly under memory-constrained environments:

  1. In addition to the resource manager's decisions on runtime usage, the limit-aware GC would collaborate to have more memory available for the kubo runtime.
  2. Until the resource manager is enabled by default, it could already increase stability and performance.

Note that 2. is written as could. Hence, my request is as follows:

  1. Perform manual tests (with and/or without resource manager) with Golang's soft memory limit set and evaluate results.
  2. Document results as recommendations for production-scale IPFS deployments.
  3. If aforementioned recommendation is positive, add automated testing.
  4. Possibly, call SetMemoryLimit when a memory limit is configured in the resource manager.
@dokterbob dokterbob added the kind/feature A new feature label Oct 5, 2022
@dokterbob
Copy link
Contributor Author

dokterbob commented Oct 5, 2022

Related: #8936 #8798
Golang's GC guide, section 'Memory limit': https://go.dev/doc/gc-guide

@Jorropo
Copy link
Contributor

Jorropo commented Oct 5, 2022

AFAIT go's soft memory limit will just run GC no matter what when you reach the limit.

GC more often cost more CPU cycles "wasted".
I don't really see what you want to test.

@guseggert guseggert added the P2 Medium: Good to have, but can wait until someone steps up label Oct 6, 2022
@fanhai
Copy link

fanhai commented Nov 5, 2022

The current default configuration of kubo under high load tends to eat all the memory it can gets until it gets until killed by the OOM, causing frequent restarts of nodes and loss of connections and service.

GOMEMLIMIT

Does it work?

@dokterbob
Copy link
Contributor Author

My question exactly. Might be able to test over the coming weeks.

@dokterbob
Copy link
Contributor Author

dokterbob commented Nov 9, 2022

AFAIT go's soft memory limit will just run GC no matter what when you reach the limit.

GC more often cost more CPU cycles "wasted". I don't really see what you want to test.

Whether in production environments (so not in theory)GOMEMLIMIT affects stability or performance. Specifically, whether it reduces OOM kills, whether it leads to more efficient memory use and better scheduling of GC, as the docs suggest it might.

Specifically, what I am hoping for is that Go will GC in time as to prevent OOM kills due to lingering garbage. Some more background: https://weaviate.io/blog/2022/08/GOMEMLIMIT-a-Game-Changer-for-High-Memory-Applications.html

@Jorropo
Copy link
Contributor

Jorropo commented Dec 3, 2022

Well I've tested, it works very well, you can't magically half kubo's memory usage because as you get closer to GOMEMLIMIT the GC will run exponentially more often until it just run continously and performance is hot garbage.

I've implemented a conservative limit that should still help there: #9451

@dokterbob
Copy link
Contributor Author

@Jorropo This is awesome! I added the suggestion of maybe setting it based on the resource manager's memory limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A new feature P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

4 participants