Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(854)

Issue 6055044: store: cache the statistics token ids

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 1 month ago by niemeyer
Modified:
12 years, 1 month ago
Reviewers:
mp+102227
Visibility:
Public.

Description

store: cache the statistics token ids This adds caching with two generations of 512 entries each. https://code.launchpad.net/~niemeyer/juju/go-store-stats-caching/+merge/102227 Requires: https://code.launchpad.net/~niemeyer/juju/go-store-stats-readonly/+merge/101673 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 30

Patch Set 2 : store: cache the statistics token ids #

Unified diffs Side-by-side diffs Delta from patch set Stats (+125 lines, -34 lines) Patch
A [revision details] View 1 1 chunk +2 lines, -0 lines 0 comments Download
M store/store.go View 1 5 chunks +71 lines, -34 lines 0 comments Download
M store/store_test.go View 1 2 chunks +52 lines, -0 lines 0 comments Download

Messages

Total messages: 4
niemeyer
Please take a look.
12 years, 1 month ago (2012-04-17 02:18:08 UTC) #1
rog
nice stuff. https://codereview.appspot.com/6055044/diff/1/store/store.go File store/store.go (right): https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode44 store/store.go:44: // Cache for statistics key words (two ...
12 years, 1 month ago (2012-04-17 09:11:14 UTC) #2
fwereade
LGTM; might be nice to make the generation size configurable (without rebuilding ;)) but I ...
12 years, 1 month ago (2012-04-17 13:42:29 UTC) #3
niemeyer
12 years, 1 month ago (2012-04-17 18:43:37 UTC) #4
*** Submitted:

store: cache the statistics token ids

This adds caching with two generations of 512 entries each.

R=rog, fwereade
CC=
https://codereview.appspot.com/6055044

https://codereview.appspot.com/6055044/diff/1/store/store.go
File store/store.go (right):

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode44
store/store.go:44: // Cache for statistics key words (two generations).
On 2012/04/17 09:11:14, rog wrote:
> i like this scheme.

Cheers.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode46
store/store.go:46: statsToken1 map[string]int
On 2012/04/17 09:11:14, rog wrote:
> i had to look quite closely to work out which one of these is fresher than the
> other. perhaps cacheTokens and cacheTokensOld ?

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode125
store/store.go:125: var t struct{ Id int "_id"; Token string "t" }
On 2012/04/17 09:11:14, rog wrote:
> gofmt

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode162
store/store.go:162: if len(s.statsToken1) == statsTokenCacheSize {
On 2012/04/17 13:42:29, fwereade wrote:
> On 2012/04/17 09:11:14, rog wrote:
> > s/==/>=/
> > defensively.
> +1

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode167
store/store.go:167: s.statsToken1 = make(map[string]int, statsTokenCacheSize)
On 2012/04/17 09:11:14, rog wrote:
> i'm slightly concerned that as soon as the size of the working set rises above
> statsTokenCacheSize, we're going to be doing this all the time, but i can't
> think of a good heuristic for adjusting the size.

We can tweak the cache size, which is an issue with any cache, but I really
don't see a real problem here. It's a single value allocated every cache-size
iterations in the worst case scenario.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode170
store/store.go:170: s.cacheMu.Unlock()
On 2012/04/17 13:42:29, fwereade wrote:
> Why not defer the unlock? (I know there aren't any early returns *now*, but
> isn't it just one more thing for a future maintainer to maybe forget?)

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode174
store/store.go:174: func (s *Store) cachedStatsTokenId(token string) (id int,
found bool) {
On 2012/04/17 13:42:29, fwereade wrote:
> On 2012/04/17 09:11:14, rog wrote:
> > the visual distinction between these two function names is very small. how
> about
> > cacheStatsToken and statsToken?
> 
> +1

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode178
store/store.go:178: if s.statsToken1 == nil {
On 2012/04/17 09:11:14, rog wrote:
> this is unnecessary.

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode178
store/store.go:178: if s.statsToken1 == nil {
On 2012/04/17 13:42:29, fwereade wrote:
> On 2012/04/17 09:11:14, rog wrote:
> > this is unnecessary.
> I don't see any guarantee that this is filled in anywhere. cached... is called
> before cache..., isn't it?

What Rog means is that it's fine to access nil maps. It originally wasn't fine,
but now it is.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode185
store/store.go:185: if s.statsToken2 == nil {
On 2012/04/17 09:11:14, rog wrote:
> this is unnecessary.

Done.

https://codereview.appspot.com/6055044/diff/1/store/store.go#newcode189
store/store.go:189: s.cacheMu.RUnlock()
On 2012/04/17 13:42:29, fwereade wrote:
> This does make perfect sense, but it stopped me short on first read... and I
> can't actually think of anything clearer :(.

Given the simplifications above, I've changed to not use defer, which made the
logic a bit nicer.

https://codereview.appspot.com/6055044/diff/1/store/store_test.go
File store/store_test.go (right):

https://codereview.appspot.com/6055044/diff/1/store/store_test.go#newcode531
store/store_test.go:531: // of 512 entries each.
On 2012/04/17 09:11:14, rog wrote:
> i don't like the fact that 512 is hard coded here. we'll likely want to adjust
> the cache size to tweak server performance. perhaps consider having an
> export_test.go that exports the max cache size.

Introducing a new file to export a single constant in this specific situation
seems unnecessary considering that this test will necessarily break if the
internal variable is changed. I agree having constants spread here is a poor
choice, though. I've introduced a genSize constant that is used across the test.
If we want to change the size, we have to tweak two locations only, and they're
both tied by the test.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b