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

Feature request: reduce memory usage #765

Closed
qdm12 opened this issue Dec 28, 2021 · 7 comments
Closed

Feature request: reduce memory usage #765

qdm12 opened this issue Dec 28, 2021 · 7 comments

Comments

@qdm12
Copy link
Owner

qdm12 commented Dec 28, 2021

What's the feature 🧐

I noticed memory usage goes to 300MB / 500MB even when using the kernel space Wireguard implementation and this is simply ridiculous (self shaming).

A pprof HTTP server should be setup to investigate why memory is so high.

Wild guesses are:

  • Server data being loaded in memory and always kept. This can be changed to be lazy loaded from files.

Extra information and references

No response

@alpe12
Copy link

alpe12 commented Jan 3, 2022

Just noticed I have 461MB usage with nordvpn openvpn here.
Going back to edgd1er/nordvpn-proxy for the time being. Only 19MB ram usage there.

@qdm12
Copy link
Owner Author

qdm12 commented Jan 22, 2022

After investigation, ram usage splits in the following:

  • Unbound: 283MB
  • Gluetun program: 35MB
    • Blacklist builder Hostnames uses 30MB (this will be addressed)
    • DNS Blacklist's getList uses 15MB (this will be addressed)
    • Built-in servers data uses 2.5MB so it is clearly not a priority (this has been worked on)
    • Rest of the program uses barely anything

Turning BLOCK_MALCIOUS=off brings down the container memory usage to about 50MB. I won't change this by default to not break compatibility.

#137 is coming soon and might improve the memory usage, although blocking hostnames/IPs at the DNS level will always incur more memory usage.

Closing this as there is not so much possible to do, except turning off DNS blocking.

@qdm12
Copy link
Owner Author

qdm12 commented Jun 19, 2022

Any option to have the blacklist, etc on disk and only active queries are cached into memory? If not maybe con1sider adding an option for a external (local container) DNS server option to off load this? E.g If someone is running 2 Gluetun tunnels only a single DNS server is required.

@amirnh2
Copy link

amirnh2 commented Aug 22, 2022

I've set the following environments:
- BLOCK_MALICIOUS=off
- BLOCK_SURVEILLANCE=off
- BLOCK_ADS=off
- DOT=off

htop shows a memory usage of about 24.5 MB for gluetun-entrypoint, and 4.2 MB for the openvpn2.5 process.

Is there any way to reduce the entry-point ram usage? or is this the lowest gluetun can go? Because I need to run many gluetun containers and I need them to consume the lowest ram possible.

@qdm12
Copy link
Owner Author

qdm12 commented Aug 22, 2022

I'll have a look. I know ~3MB are used to have all the server data in memory at runtime, and that can be moved to lazy loading from disk. But apart from that, there might not be a way to reduce it further as I remember.

@amirnh2
Copy link

amirnh2 commented Aug 23, 2022

I hope there's a way.

Thank you for this great repository.

@qdm12
Copy link
Owner Author

qdm12 commented Sep 8, 2022

You can dig into it by profiling the heap following steps in this new wiki page: https://github.com/qdm12/gluetun/wiki/Profiling
Maybe you can spot a place where most MBs of memory go. Although the Go runtime probably use ~10MB anyway, so it might not be very possible to lower memory usage that much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@alpe12 @qdm12 @amirnh2 and others