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
Changes from 3 commits
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
46 changes: 30 additions & 16 deletions posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ func (ir *incrRollupi) Process(closer *y.Closer) {
defer limiter.Stop()
cleanupTick := time.NewTicker(5 * time.Minute)
defer cleanupTick.Stop()
forceRollupTick := time.NewTicker(2 * time.Second)
defer forceRollupTick.Stop()

var batch *[][]byte

dorollup := func() {
currTs := time.Now().Unix()
for _, key := range *batch {
hash := z.MemHash(key)
if elem := m[hash]; currTs-elem >= 10 {
// Key not present or Key present but last roll up was more than 10 sec ago.
// Add/Update map and rollup.
m[hash] = currTs
if err := ir.rollUpKey(writer, key); err != nil {
glog.Warningf("Error %v rolling up key %v\n", err, key)
}
}
}
// clear the batch and put it back in Sync keysPool
*batch = (*batch)[:0]
ir.keysPool.Put(batch)
}

for {
select {
Expand All @@ -125,23 +147,15 @@ func (ir *incrRollupi) Process(closer *y.Closer) {
delete(m, hash)
}
}
case batch := <-ir.keysCh:
currTs := time.Now().Unix()
for _, key := range *batch {
hash := z.MemHash(key)
if elem := m[hash]; currTs-elem >= 10 {
// Key not present or Key present but last roll up was more than 10 sec ago.
// Add/Update map and rollup.
m[hash] = currTs
if err := ir.rollUpKey(writer, key); err != nil {
glog.Warningf("Error %v rolling up key %v\n", err, key)
}
}
case <-forceRollupTick.C:
batch = ir.keysPool.Get().(*[][]byte)
if len(*batch) > 0 {
dorollup()
} else {
ir.keysPool.Put(batch)
}
// clear the batch and put it back in Sync keysPool
*batch = (*batch)[:0]
ir.keysPool.Put(batch)

case batch = <-ir.keysCh:
dorollup()
// throttle to 1 batch = 64 rollups per 100 ms.
<-limiter.C
}
Expand Down