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

Fix memory leak in distributor due to cluster label #4739

Merged

Conversation

harry671003
Copy link
Contributor

@harry671003 harry671003 commented May 12, 2022

What this PR does:
The HA cluster label is exposed through the distributor metrics. This can cause memory leak when one tenant sends a lot of different clusters. The metrics is only cleaned up after 30 mins.

The memory is leaked because the yoloString in the request is kept alive for a longer period.

Yolo

The following is the memory consumed by the distributor over time without cloning the cluster label.
Without the fix

The following is the memory consumed by distributor when cluster label was cloned.
Cloning the cluster label

The above leak in snappyDecode appears to have disappeared.
Leak is fixed

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@harry671003 harry671003 force-pushed the distributor-memory-leak branch from 15200a9 to 899cbce Compare May 12, 2022 04:48
@alanprot
Copy link
Member

LGTM

pkg/distributor/ha_tracker.go Outdated Show resolved Hide resolved
@@ -19,3 +21,11 @@ func StringsMap(values []string) map[string]bool {
}
return out
}

// StringsClone returns a copy input s
// see: https://github.com/golang/go/blob/master/src/strings/clone.go
Copy link
Contributor

Choose a reason for hiding this comment

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

:-) nice! We should update Go one day.

@harry671003 harry671003 force-pushed the distributor-memory-leak branch from 899cbce to 687f4e4 Compare May 12, 2022 17:21
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
@harry671003 harry671003 force-pushed the distributor-memory-leak branch from 687f4e4 to c876750 Compare May 12, 2022 17:41
@alvinlin123 alvinlin123 merged commit 5b7d3c1 into cortexproject:master May 12, 2022
@bboreham
Copy link
Contributor

Thanks for this. Note we also have a function with the same intent here:

func copyString(s string) string {
return string([]byte(s))
}

In Go it is fairly common to copy a tiny function rather than exposing it - "a little copying is better than a little dependency".

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

Successfully merging this pull request may close these issues.

4 participants