Skip to content

Commit

Permalink
Lock the block cache in shared mode for retrieval
Browse files Browse the repository at this point in the history
The Clock-PRO algorithm doesn't require exclusive access to internal
state on hits. Switch to using a RWMutex which reduces a source of
contention in cached workloads.

For a concurrent scan workload, performance before this commit was:

____optype__elapsed_____ops(total)___ops/sec(cum)
  scan_100   120.0s      151736009      1264384.6

After:

____optype__elapsed_____ops(total)___ops/sec(cum)
  scan_100   120.0s      170326751      1419354.7

That's a 12% improvement in throughput.

See #11
  • Loading branch information
petermattis committed Jul 5, 2019
1 parent 6a090fb commit a700ad5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cache/clockpro.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type WeakHandle interface {
}

type shard struct {
mu sync.Mutex
mu sync.RWMutex

maxSize int64
coldSize int64
Expand All @@ -166,10 +166,9 @@ type shard struct {
}

func (c *shard) Get(fileNum, offset uint64) []byte {
c.mu.Lock()
defer c.mu.Unlock()

c.mu.RLock()
e := c.blocks[key{fileNum: fileNum, offset: offset}]
c.mu.RUnlock()
if e == nil {
return nil
}
Expand Down

0 comments on commit a700ad5

Please sign in to comment.