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

[bug] new cgroups-related error on start #2983

Closed
mirabilos opened this issue Jun 9, 2024 · 9 comments · Fixed by #3002
Closed

[bug] new cgroups-related error on start #2983

mirabilos opened this issue Jun 9, 2024 · 9 comments · Fixed by #3002
Labels
bug Something isn't working

Comments

@mirabilos
Copy link
Contributor

Describe the bug with a clear and concise description of what the bug is.

2024/06/09 20:38:43 ERROR failed to set GOMEMLIMIT package=github.com/KimMachineGun/automemlimit/memlimit error="failed to set GOMEMLIMIT: cgroups: cgroup mountpoint does not exist"

What's your GoToSocial Version?

GoToSocial 0.16.0-rc1+git-048339a 🦥

GoToSocial Arch

amd64 binary

What happened?

I upgraded, and this message on start is new.

What you expected to happen?

No response

How to reproduce it?

No response

Anything else we need to know?

This is Debian with sysvinit, so no cgroups in use or prepared for use.

@mirabilos mirabilos added the bug Something isn't working label Jun 9, 2024
@mirabilos
Copy link
Contributor Author

From peeking at https://github.com/KimMachineGun/automemlimit?tab=readme-ov-file and https://tip.golang.org/doc/gc-guide#Memory_limit it sounds to me like everyone not running GtS inside cgroup’d Docker (with already-configured limits?) needs to set the memory limits themselves, so other programs running on the same machine (at least Apache httpd 2 reverse proxy and PostgreSQL, but often also other services) aren’t moved out?

If so, should there be a guide on how (export GOMEMLIMIT?) and sizing?

@mirabilos
Copy link
Contributor Author

That being said, as-is it uses about 150 MiB RSS, which is fine.

@tsmethurst
Copy link
Contributor

The only thing that's changed from previous releases is that this is now logged, but it really shouldn't be since it's not actually an error, so we just need to figure out how to suppress it to avoid confusing people.

should there be a guide on how (export GOMEMLIMIT?) and sizing?

Not sure how necessary a guide is. We have a little note here with some links: https://docs.gotosocial.org/en/latest/getting_started/#memory-and-cpu-limits. Likely the sort of users who'd want to create those sorts of constraints already know what they're doing.

@daenney
Copy link
Member

daenney commented Jun 12, 2024

From peeking at https://github.com/KimMachineGun/automemlimit?tab=readme-ov-file and https://tip.golang.org/doc/gc-guide#Memory_limit it sounds to me like everyone not running GtS inside cgroup’d Docker (with already-configured limits?) needs to set the memory limits themselves, so other programs running on the same machine (at least Apache httpd 2 reverse proxy and PostgreSQL, but often also other services) aren’t moved out?

The GOMEMLIMIT sets a maximum amount of memory the process may use, and by default that's unconstrained. But that's no different from Apache2 or PostgreSQL, which aren't constrained in their memory allocations or CPU usage either. Just because the Go runtime isn't constrained doesn't mean it's going to allocate or consume everything so you can leave the limit unset just fine. When all processes run without resource constraints you can end up in an OOM situation triggered by any of those processes, and the kernel will decide on its victim based on its own heuristics at that point.

When running in cgroups, whether manually managed or as a consequence of running a container, you may set resource constraints on the cgroup either directly or by specifying something like 256MB of memory, amount of vCPUs etc. when starting a container. However, running within a cgroup the Go runtime still sees the hosts' total available memory, total CPU etc. The Go runtime isn't cgroup-aware. This is unfortunate as it can cause the process to try to use resources beyond what it can use and get killed as the runtime ends up making incorrect decisions and isn't able to adjust the GC based on the actual resources available. By passing on any cgroup limits to the Go runtime, it becomes aware of the resource constraints its under and can tweak its behaviour to match.

@mirabilos
Copy link
Contributor Author

mirabilos commented Jun 12, 2024 via email

@daenney
Copy link
Member

daenney commented Jun 12, 2024

Yup, the library introduced a change that causes that error to be logged by them. We just need to silence their logger.

daenney added a commit that referenced this issue Jun 12, 2024
The memlimit package started to log any error returned by automemlimit.
This updates our implementation to call SetGoMemLimitWithOpts() instead
which uses the same defaults as automemlimit except for being
initialised with a noop logger.

We check the returned error for a particular substring, as when cgroups
isn't available even when running on a Linux system that's not a
problem. If it's anything but that error, we log it at the warning
level so that admins can still diagnose other cgroup related issues.

Fixes #2983
@daenney
Copy link
Member

daenney commented Jun 12, 2024

I've raised #3002 which should fix this. Feel free to try it out if you like!

daenney added a commit that referenced this issue Jun 12, 2024
The memlimit package started to log any error returned by automemlimit.
This updates our implementation to call SetGoMemLimitWithOpts() instead
which uses the same defaults as automemlimit except for being
initialised with a noop logger.

We check the returned error for a particular substring, as when cgroups
isn't available even when running on a Linux system that's not a
problem. If it's anything but that error, we log it at the warning
level so that admins can still diagnose other cgroup related issues.

Fixes #2983
@mirabilos
Copy link
Contributor Author

That, or raise the issue with them, so they can exclude such errors.

But the idea of præfixing all messages from their logger when displaying them in the GtS log (and stripping this one) is also nice.

@mirabilos
Copy link
Contributor Author

Yup, is fixed in rc3, thanks!

nyarla pushed a commit to nyarla/gotosocial-modded that referenced this issue Jun 19, 2024
The memlimit package started to log any error returned by automemlimit.
This updates our implementation to call SetGoMemLimitWithOpts() instead
which uses the same defaults as automemlimit except for being
initialised with a noop logger.

We check the returned error for a particular substring, as when cgroups
isn't available even when running on a Linux system that's not a
problem. If it's anything but that error, we log it at the warning
level so that admins can still diagnose other cgroup related issues.

Fixes superseriousbusiness#2983

Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
nyarla pushed a commit to nyarla/gotosocial-modded that referenced this issue Jun 19, 2024
The memlimit package started to log any error returned by automemlimit.
This updates our implementation to call SetGoMemLimitWithOpts() instead
which uses the same defaults as automemlimit except for being
initialised with a noop logger.

We check the returned error for a particular substring, as when cgroups
isn't available even when running on a Linux system that's not a
problem. If it's anything but that error, we log it at the warning
level so that admins can still diagnose other cgroup related issues.

Fixes superseriousbusiness#2983

Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants