Skip to content

Add life expectancy histogram#182

Merged
manishrjain merged 6 commits intomasterfrom
mrjn/life-hist
Aug 18, 2020
Merged

Add life expectancy histogram#182
manishrjain merged 6 commits intomasterfrom
mrjn/life-hist

Conversation

@manishrjain
Copy link
Contributor

@manishrjain manishrjain commented Aug 18, 2020

If cache is too small, keys can enter and leave very quickly. This results in poor cache usage. Adding a life expectancy histogram to track a sample of keys from admission into cache to eviction. If we see too many keys getting evicted quickly, (along with miss ratio) that's a clear signal that cache size is too small. This would help a user tweak cache size better.


This change is Reviewable

Copy link
Contributor

@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.

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @anurags92, @karlmcguire, and @manishrjain)


cache.go, line 326 at r1 (raw file):

	c.Metrics.updateLatency(hist)

	addToHist := func(key uint64) {

Do we want to still do this even if metrics are disabled? We'll be adding to the map but ultimately discarding the data.


cache.go, line 339 at r1 (raw file):

	onEvict := func(i *Item) {
		if ts, has := startTs[i.Key]; has {
			hist.Update(int64(time.Since(ts) / time.Second))

Add a comment here so it's clearer what the histogram is keeping track of. Like:

// Add the amount of time this item spent in the cache to the histogram.

z/histogram.go, line 83 at r1 (raw file):

}

// PrintHistogram prints the histogram data in a human-readable format.

Update docstring.

Copy link
Contributor

@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.

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @anurags92, @karlmcguire, @manishrjain, and @martinmr)

@martinmr martinmr self-requested a review August 18, 2020 14:10
@manishrjain manishrjain merged commit 1940d54 into master Aug 18, 2020
@manishrjain manishrjain deleted the mrjn/life-hist branch August 18, 2020 14:17
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