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

fix(rollups): rollup a batch if more than 2 seconds elapsed since last batch #6118

Merged
merged 5 commits into from
Aug 4, 2020
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
8 changes: 7 additions & 1 deletion posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,22 @@ func (ir *incrRollupi) rollUpKey(writer *TxnWriter, key []byte) error {
return writer.Write(&bpb.KVList{Kv: kvs})
}

var lastSentTs int64 // keep track of ts of last batch rolled up.
func (ir *incrRollupi) addKeyToBatch(key []byte) {
batch := ir.keysPool.Get().(*[][]byte)
*batch = append(*batch, key)
if len(*batch) < 64 {
sent := atomic.LoadInt64(&lastSentTs)
now := time.Now().Unix()

// Rollup only if batch len is 64 or it has been more than 2 seconds since last batch.
if now-sent < 2 && len(*batch) < 64 {
ir.keysPool.Put(batch)
return
}

select {
case ir.keysCh <- batch:
atomic.StoreInt64(&lastSentTs, now)
default:
// Drop keys and build the batch again. Lossy behavior.
*batch = (*batch)[:0]
Expand Down
7 changes: 7 additions & 0 deletions posting/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import (
"github.com/stretchr/testify/require"
)

func BenchmarkIncrRollupAtomic(b *testing.B) {
buf := []byte("key")
for n := 0; n < b.N; n++ {
IncrRollup.addKeyToBatch(buf)
}
}

func TestRollupTimestamp(t *testing.T) {
key := x.DataKey("rollup", 1)
// 3 Delta commits.
Expand Down