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

runtime: make max heap size configurable #9849

Closed
owenthereal opened this issue Feb 12, 2015 · 12 comments
Closed

runtime: make max heap size configurable #9849

owenthereal opened this issue Feb 12, 2015 · 12 comments

Comments

@owenthereal
Copy link

I'm looking for a way to limit the max memory consumption of a Go program, say the memory doesn't exceed X. Further discussion is here.

Does it make sense to make runtime.MaxMem configurable?

  1. What version of Go are you using (go version)?
    1.4.1.
  2. What operating system and processor architecture are you using?
    64 bit Linux.
  3. What did you do?
    I tried to limit the memory usage of my Go program. The server only has 1GB. The Go process was killed by the monitor process and the server was restarted.
  4. What did you expect to see?
    I expect there's a variable in Go runtime to set this limit, e.g., runtime.MaxMem = x.
  5. What did you see instead?
    I couldn't find a way to limit memory usage in Go. ulimit may be one option but it's not cross platform. Also ulimit requires root access and I don't have it since the server is hosted on Heroku.

/cc @davecheney

@owenthereal owenthereal changed the title runtime: Make Heap Size Configurable runtime: Make Max Heap Size Configurable Feb 12, 2015
@bradfitz
Copy link
Contributor

The issue tracker isn't a support forum. Please move this to golang-nuts@ or StackOverflow.

The answer will probably be ulimit.

@owenthereal
Copy link
Author

The issue tracker isn't a support forum. Please move this to golang-nuts@ or StackOverflow.

This is not a supporting question. It's a feature request...

@owenthereal
Copy link
Author

And ulimit is not cross platform...

@bradfitz
Copy link
Contributor

Fair enough, I suppose. Although I'm not sure how much Go should try to be your operating system, as opposed to just recognizing and respecting the limits you've put on the process in your operating system. Will reopen.

@bradfitz bradfitz reopened this Feb 12, 2015
@c4milo
Copy link
Member

c4milo commented Feb 12, 2015

@bradfitz I think it would be worth writing a CONTRIBUTING guide here in GitHub so that its link shows up every time anybody is about to create a new issue. https://github.com/blog/1184-contributing-guidelines

@bradfitz
Copy link
Contributor

@c4milo
Copy link
Member

c4milo commented Feb 12, 2015

Clueless me. Sorry.

@owenthereal
Copy link
Author

I added more description. However, I don't think the confusion was caused by not having filled the issue template.

@bradfitz
Copy link
Contributor

Actually the issue is much better now, thanks.

@bradfitz
Copy link
Contributor

See also: #5049 (runtime: respect memory ulimit more precisely).

@RLH
Copy link
Contributor

RLH commented Feb 12, 2015

Adding knobs like this can certainly seem attractive but they come with costs in the development cycle. A simple binary knob doubles the number of tests that the Go runtime team has to run. We run those tests a dozen times a day and leave them running every night when we go home. Each CL runs them across more than a dozen HW/OS configurations. This request suggests a non-binary knob where reasonable testing will require more than two values which is even worse. The bar to adding knobs in Go is, and should be, very high.
It's worse for the application programmer who now turns knobs all day instead of dealing with reducing the amount of live data which in turn will reduce the size of the heap. The GC will try to keep total heap size at about 2X live heap which is what the runtime team is tuning for.

@rsc
Copy link
Contributor

rsc commented Apr 10, 2015

Duplicate of #5049

@rsc rsc changed the title runtime: Make Max Heap Size Configurable runtime: make max heap size configurable Apr 10, 2015
@rsc rsc closed this as completed Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants