Skip to content

Commit

Permalink
Lock lru before write; add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Lozinski committed Oct 26, 2016
1 parent 862ce95 commit e9d36ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prepared_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (p *preparedLRU) execIfMissing(key string, fn func(lru *lru.Cache) *infligh
return val.(*inflightPrepare), true
}

p.mu.Lock()
defer p.mu.Unlock()
return fn(p.lru), false
}

Expand Down
22 changes: 22 additions & 0 deletions prepared_cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gocql

import (
"testing"

"github.com/gocql/gocql/internal/lru"
)

func BenchmarkLRU(b *testing.B) {
pl := preparedLRU{
lru: lru.New(10),
}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
pl.execIfMissing("foo", func(c *lru.Cache) *inflightPrepare {
c.Add("foo", (*inflightPrepare)(nil))
return nil
})
}
})
}

0 comments on commit e9d36ad

Please sign in to comment.