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: cheaper alternative to runtime.ReadMemStats #13613

Closed
mkevac opened this issue Dec 14, 2015 · 9 comments
Closed

runtime: cheaper alternative to runtime.ReadMemStats #13613

mkevac opened this issue Dec 14, 2015 · 9 comments

Comments

@mkevac
Copy link
Contributor

mkevac commented Dec 14, 2015

Hi.

runtime.ReadMemStats() calls stopTheWorld inside(), so it is very expensive to call it often (see https://github.com/mkevac/debugcharts). Especially in a production system.

I would like to see cheaper but maybe not so accurate alternative if it's possible.

Thanks.

@ianlancetaylor ianlancetaylor changed the title Cheaper alternative to runtime.ReadMemStats() runtime: cheaper alternative to runtime.ReadMemStats Dec 14, 2015
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Dec 14, 2015
@ianlancetaylor
Copy link
Contributor

CC @dvyukov @aclements

@dvyukov
Copy link
Member

dvyukov commented Dec 14, 2015

What parts of MemStats are you interested in?

@mkevac
Copy link
Contributor Author

mkevac commented Dec 14, 2015

This particular package uses Alloc, PauseNs and NumGC to graph memory usage and GC pauses.
But I am not sure that patch, if one is possible, should be tied to only my use case.

@dup2X
Copy link

dup2X commented Mar 14, 2016

hack go src code?

@heschi
Copy link
Contributor

heschi commented Dec 16, 2016

I took an execution trace from an application with a 15-30GB heap, and a call to runtime.ReadMemStats() paused it for about 40 ms. We don't want to give up monitoring memory usage and GC performance, but we also don't want to pause to do it. So some improvement in this area would be appreciated.

If it helps, a non-STW version of ReadMemStats that only provided roughly accurate numbers, or left out the more fine-grained information entirely, might still be fine for most purposes.

@aclements
Copy link
Member

I haven't thought deeply about this, but I suspect ReadMemStats can be made dramatically more efficient without sacrificing accuracy. It may still have to stop the world very briefly to collect distributed statistics, but that would be much better than the current STW walk it does over the entire heap.

@Dieterbe
Copy link
Contributor

Dieterbe commented Dec 22, 2016

Hello, I'm very interested as well. I use runtime.ReadMemStats in two places:

  1. i run some code every 1s to 60s that checks .Sys only and dumps a memory profile once a threshold is breached (https://github.com/Dieterbe/profiletrigger/blob/master/heap/heap.go)
  2. my service reports its own internal memory stats every second. currently that is the following (though subject to change in the future)
m.mem.TotalAlloc # nice to plot "allocation rate" (the derived version of this)
m.mem.Alloc # quite useful
m.mem.Sys # very useful
m.mem.NumGC
m.mem.GCCPUFraction # this one hasn't been particularly useful. not sure what to do with it. might stop looking at it
m.mem.HeapObjects # this should correlate somewhat to GC workload, haven't used it much yet
m.mem.PauseNs 

I've seen some cpu profiles where runtime.ReadMemStats shows up as >=10% (cumulatively), but also sometimes it's completely absent from the profile. I haven't figured out yet why or what workloads trigger this function to take more time.

Either way, very interested in having this one optimized 👍

@gopherbot
Copy link

CL https://golang.org/cl/34937 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/34936 mentions this issue.

@aclements aclements modified the milestones: Go1.9Early, Go1.9Maybe Jan 6, 2017
gopherbot pushed a commit that referenced this issue Mar 4, 2017
The gcstats structure is no longer consumed by anything and no longer
tracks statistics that are particularly relevant to the concurrent
garbage collector. Remove it. (Having statistics is probably a good
idea, but these aren't the stats we need these days and we don't have
a way to get them out of the runtime.)

In preparation for #13613.

Change-Id: Ib63e2f9067850668f9dcbfd4ed89aab4a6622c3f
Reviewed-on: https://go-review.googlesource.com/34936
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Rick Hudson <rlh@golang.org>
@golang golang locked and limited conversation to collaborators Mar 4, 2018
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

9 participants