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

optimize migrator's executeWriteFuncs #1124

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
53 changes: 30 additions & 23 deletions go/logic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,32 +1279,39 @@ func (this *Migrator) executeWriteFuncs() error {
return err
}
}
default:
case copyRowsFunc := <-this.copyRowsQueue:
if err := this.drainApplierEventQueue(); err != nil {
return this.migrationContext.Log.Errore(err)
}
{
select {
case copyRowsFunc := <-this.copyRowsQueue:
{
copyRowsStartTime := time.Now()
// Retries are handled within the copyRowsFunc
if err := copyRowsFunc(); err != nil {
return this.migrationContext.Log.Errore(err)
}
if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 {
copyRowsDuration := time.Since(copyRowsStartTime)
sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds())
sleepTime := time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond
time.Sleep(sleepTime)
}
}
default:
{
// Hmmmmm... nothing in the queue; no events, but also no row copy.
// This is possible upon load. Let's just sleep it over.
this.migrationContext.Log.Debugf("Getting nothing in the write queue. Sleeping...")
time.Sleep(time.Second)
}
copyRowsStartTime := time.Now()
// Retries are handled within the copyRowsFunc
if err := copyRowsFunc(); err != nil {
return this.migrationContext.Log.Errore(err)
}
if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 {
copyRowsDuration := time.Since(copyRowsStartTime)
sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds())
sleepTime := time.Duration(sleepTimeNanosecondFloat64) * time.Nanosecond
time.Sleep(sleepTime)
}
}
}
}
}

func (this *Migrator) drainApplierEventQueue() error {
for {
select {
case eventStruct := <-this.applyEventsQueue:
{
this.throttler.throttle(nil)
if err := this.onApplyEventStruct(eventStruct); err != nil {
timvaillancourt marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}
default:
return nil
}
}
}
Expand Down