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

Only run GC if the memory has shrunk or expanded by more than 0.5GB. #4075

Merged
merged 2 commits into from
Sep 27, 2019

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Sep 27, 2019

The GC is being manually called too many times. This change reduces the
number of times it's run by only calling it if the allocated memory in
the heap has shrunk or expanded by more than half a GB and if it's not
being run in the last ten seconds.


This change is Reviewable

The GC is being manually called too many times. This change reduces the
number of times it's run by only calling it if the allocated memory in
the heap has shrunk or expanded by more than half a GB and if it's not
being run in the last ten seconds.
@martinmr martinmr requested review from manishrjain and a team as code owners September 27, 2019 00:57
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ A review job has been created and sent to the PullRequest network.


@martinmr you can click here to see the review status or cancel the code review job.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

:lgtm: One VI comment.

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @martinmr)


dgraph/main.go, line 41 at r1 (raw file):

		defer ticker.Stop()

		minDiff := uint64(5e8)

512 << 20


dgraph/main.go, line 55 at r1 (raw file):

			}

			if ms.NumGC >= lastNum {

Remove the equals. Update the if below.


dgraph/main.go, line 62 at r1 (raw file):

				// more than 0.5GB since the last time the memory stats were collected.
				lastNum = ms.NumGC
			} else {

if ms.NumGC == lastNum

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

A good optimization. A few minor comments.


Reviewed with ❤️ by PullRequest

dgraph/main.go Outdated
diff = lastMs.HeapAlloc - ms.HeapAlloc
}

if ms.NumGC >= lastNum {
Copy link

Choose a reason for hiding this comment

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

Same issue with naming here. NumGC doesn't seem intuitive to understand here.

dgraph/main.go Outdated
@@ -38,20 +38,35 @@ func main() {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

minDiff := uint64(5e8)
var lastMs runtime.MemStats
var lastNum uint32
Copy link

Choose a reason for hiding this comment

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

It would be useful for this variable name to be a bit more clear such as lastRunTimestamp.

dgraph/main.go Outdated
@@ -38,20 +38,35 @@ func main() {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

minDiff := uint64(5e8)
Copy link

Choose a reason for hiding this comment

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

I'm finding that 5e8 is 0.47 GB (2 s.f.). Why this for 0.5 GB?

Copy link
Contributor Author

@martinmr martinmr left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @manishrjain and @pullrequest[bot])


dgraph/main.go, line 41 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

512 << 20

Done.


dgraph/main.go, line 41 at r1 (raw file):

Previously, pullrequest[bot] wrote…

I'm finding that 5e8 is 0.47 GB (2 s.f.). Why this for 0.5 GB?

Done


dgraph/main.go, line 43 at r1 (raw file):

Previously, pullrequest[bot] wrote…

It would be useful for this variable name to be a bit more clear such as lastRunTimestamp.

Renamed to lastNumGC to match the naming in MemStats


dgraph/main.go, line 55 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Remove the equals. Update the if below.

Done.


dgraph/main.go, line 55 at r1 (raw file):

Previously, pullrequest[bot] wrote…

Same issue with naming here. NumGC doesn't seem intuitive to understand here.

Cannot rename this variable.


dgraph/main.go, line 62 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

if ms.NumGC == lastNum

Done.

@martinmr martinmr merged commit b6b2c6e into master Sep 27, 2019
@martinmr martinmr deleted the martinmr/check-memory-before-gc branch September 27, 2019 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants