Skip to content

Commit

Permalink
Properly measure time spent in LRU
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Artoul committed Aug 28, 2018
1 parent 6096598 commit 81ae4a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
14 changes: 7 additions & 7 deletions src/dbnode/storage/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ type dbBlock struct {
}

type listState struct {
next DatabaseBlock
prev DatabaseBlock
nextPrevUpdatedAtUnixNano int64
next DatabaseBlock
prev DatabaseBlock
enteredListAtUnixNano int64
}

// NewDatabaseBlock creates a new DatabaseBlock instance.
Expand Down Expand Up @@ -488,13 +488,13 @@ func (b *dbBlock) setPrev(value DatabaseBlock) {
}

// Should only be used by the WiredList.
func (b *dbBlock) nextPrevUpdatedAtUnixNano() int64 {
return b.listState.nextPrevUpdatedAtUnixNano
func (b *dbBlock) enteredListAtUnixNano() int64 {
return b.listState.enteredListAtUnixNano
}

// Should only be used by the WiredList.
func (b *dbBlock) setNextPrevUpdatedAtUnixNano(value int64) {
b.listState.nextPrevUpdatedAtUnixNano = value
func (b *dbBlock) setEnteredListAtUnixNano(value int64) {
b.listState.enteredListAtUnixNano = value
}

// wiredListEntry is a snapshot of a subset of the block's state that the WiredList
Expand Down
48 changes: 24 additions & 24 deletions src/dbnode/storage/block/block_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/dbnode/storage/block/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ type databaseBlock interface {
setNext(block DatabaseBlock)
prev() DatabaseBlock
setPrev(block DatabaseBlock)
nextPrevUpdatedAtUnixNano() int64
setNextPrevUpdatedAtUnixNano(value int64)
enteredListAtUnixNano() int64
setEnteredListAtUnixNano(value int64)
wiredListEntry() wiredListEntry
}

Expand Down
6 changes: 3 additions & 3 deletions src/dbnode/storage/block/wired_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ func (l *WiredList) insertAfter(v, at DatabaseBlock) {
at.setNext(v)
v.setPrev(at)
v.setNext(n)
v.setNextPrevUpdatedAtUnixNano(now.UnixNano())
n.setPrev(v)
l.length++

Expand Down Expand Up @@ -292,8 +291,8 @@ func (l *WiredList) insertAfter(v, at DatabaseBlock) {

l.metrics.evicted.Inc(1)

lastUpdatedAt := time.Unix(0, bl.nextPrevUpdatedAtUnixNano())
l.metrics.evictedAfterDuration.Record(now.Sub(lastUpdatedAt))
enteredListAt := time.Unix(0, bl.enteredListAtUnixNano())
l.metrics.evictedAfterDuration.Record(now.Sub(enteredListAt))

bl = nextBl
}
Expand All @@ -320,6 +319,7 @@ func (l *WiredList) pushBack(v DatabaseBlock) {

l.metrics.inserted.Inc(1)
l.insertAfter(v, l.root.prev())
v.setEnteredListAtUnixNano(l.nowFn().UnixNano())
}

func (l *WiredList) moveToBack(v DatabaseBlock) {
Expand Down

0 comments on commit 81ae4a8

Please sign in to comment.