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: automatically set GOMEMLIMIT #6809

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dunglas
Copy link
Collaborator

@dunglas dunglas commented Jan 25, 2025

Setting the Go runtime memory limit can improve significantly the performance of Caddy (and FrankenPHP and Mercure, according to our tests), especially on low-resources machines and containers.

This patch uses github.com/KimMachineGun/automemlimit to automatically find a good limit using the currently configured groups. This is especially useful when setting limits to containers using Docker, Kubernetes, LXC, and the like.

This PR is similar to #6047, which does the same things go the max number of processors.

Thanks to @flovntp for the idea and for finding this library!

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks Kevin! Do you think we could add a comment to this code (and maybe it could be shared with the gomaxprocs code above it) since I don't think it's obvious why it's useful? Then we will merge!

@mholt mholt added the optimization 📉 Performance or cost improvements label Jan 26, 2025
@dunglas
Copy link
Collaborator Author

dunglas commented Jan 26, 2025

@mholt, done.

I also added logs for GOMAXPROCS to improve the overall experience. Commands now start with something like this:

2025/01/26 21:11:59.838 INFO    maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined
2025/01/26 21:11:59.838 INFO    GOMEMLIMIT is updated   {"package": "github.com/KimMachineGun/automemlimit/memlimit", "GOMEMLIMIT": 15461882265, "previous": 9223372036854775807}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization 📉 Performance or cost improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants