Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache snapshotting performance improvements #7830

Merged
merged 8 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplifications and cleanup
  • Loading branch information
jwilder committed Jan 12, 2017
commit 06a8fd6ca2389428d4ead90a296139f54f2fe684
4 changes: 2 additions & 2 deletions tsdb/engine/tsm1/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func (c *Cache) Snapshot() (*Cache, error) {
snapshotSize := c.Size()

// Save the size of the snapshot on the snapshot cache
c.snapshot.size = snapshotSize
atomic.StoreUint64(&c.snapshot.size, snapshotSize)
// Save the size of the snapshot on the live cache
c.snapshotSize = snapshotSize
atomic.StoreUint64(&c.snapshotSize, snapshotSize)

// Reset the cache's store.
c.store.reset()
Expand Down
10 changes: 3 additions & 7 deletions tsdb/engine/tsm1/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,14 +1320,12 @@ func NewCacheKeyIterator(cache *Cache, size int) KeyIterator {
}

func (c *cacheKeyIterator) encode() {
concurrency := runtime.NumCPU()
concurrency := runtime.GOMAXPROCS(0)
n := len(c.ready)

// Divide the keyset across each CPU
chunkSize := 128
idx := uint64(0)
var wg sync.WaitGroup
wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
// Run one goroutine per CPU and encode a section of the key space concurrently
go func() {
Expand All @@ -1342,10 +1340,8 @@ func (c *cacheKeyIterator) encode() {
}
c.encodeRange(start, end)
}
wg.Done()
}()
}
wg.Wait()
}

func (c *cacheKeyIterator) encodeRange(start, stop int) {
Expand Down Expand Up @@ -1373,7 +1369,7 @@ func (c *cacheKeyIterator) encodeRange(start, stop int) {
err: err,
})
}
// Notify this key is full encoded
// Notify this key is fully encoded
c.ready[i] <- struct{}{}
}
}
Expand All @@ -1387,7 +1383,7 @@ func (c *cacheKeyIterator) Next() bool {
}
c.i++

if c.i >= len(c.order) {
if c.i >= len(c.ready) {
return false
}

Expand Down