ETA calculation based on past hour's progress (moving window)
This commit is contained in:
parent
cf08babc55
commit
90d557be9e
@ -70,6 +70,8 @@ type Migrator struct {
|
||||
applyEventsQueue chan tableWriteFunc
|
||||
|
||||
handledChangelogStates map[string]bool
|
||||
|
||||
progressHistory *ProgressHistory
|
||||
}
|
||||
|
||||
func NewMigrator() *Migrator {
|
||||
@ -84,6 +86,7 @@ func NewMigrator() *Migrator {
|
||||
copyRowsQueue: make(chan tableWriteFunc),
|
||||
applyEventsQueue: make(chan tableWriteFunc, applyEventsQueueBuffer),
|
||||
handledChangelogStates: make(map[string]bool),
|
||||
progressHistory: NewProgressHistory(),
|
||||
}
|
||||
return migrator
|
||||
}
|
||||
@ -782,19 +785,18 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
|
||||
}
|
||||
|
||||
var etaSeconds float64 = math.MaxFloat64
|
||||
this.progressHistory.markState()
|
||||
eta := "N/A"
|
||||
if progressPct >= 100.0 {
|
||||
eta = "due"
|
||||
} else if progressPct >= 1.0 {
|
||||
elapsedRowCopySeconds := this.migrationContext.ElapsedRowCopyTime().Seconds()
|
||||
totalExpectedSeconds := elapsedRowCopySeconds * float64(rowsEstimate) / float64(totalRowsCopied)
|
||||
etaSeconds = totalExpectedSeconds - elapsedRowCopySeconds
|
||||
if etaSeconds >= 0 {
|
||||
etaDuration := time.Duration(etaSeconds) * time.Second
|
||||
} else if etaTime := this.progressHistory.getETA(); progressPct >= 0.1 && !etaTime.IsZero() {
|
||||
etaDuration := etaTime.Sub(time.Now())
|
||||
eta = base.PrettifyDurationOutput(etaDuration)
|
||||
} else {
|
||||
eta = "due"
|
||||
etaSeconds = etaDuration.Seconds()
|
||||
}
|
||||
|
||||
if etaSeconds < 0 {
|
||||
eta = "due"
|
||||
}
|
||||
|
||||
state := "migrating"
|
||||
|
@ -7,6 +7,7 @@ package logic
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/github/gh-ost/go/base"
|
||||
@ -101,5 +102,14 @@ func (this *ProgressHistory) getETA() (eta time.Time) {
|
||||
if !this.hasEnoughData() {
|
||||
return eta
|
||||
}
|
||||
|
||||
oldest := this.oldestState()
|
||||
newest := this.newestState()
|
||||
rowsEstimate := atomic.LoadInt64(&this.migrationContext.RowsEstimate) + atomic.LoadInt64(&this.migrationContext.RowsDeltaEstimate)
|
||||
ratio := float64(rowsEstimate-oldest.rowsCopied) / float64(newest.rowsCopied-oldest.rowsCopied)
|
||||
// ratio is also float64(totaltime-oldest.mark) / float64(newest.mark-oldest.mark)
|
||||
totalTimeNanosecondsFromOldestMark := ratio * float64(newest.mark.Sub(oldest.mark).Nanoseconds())
|
||||
eta = oldest.mark.Add(time.Duration(totalTimeNanosecondsFromOldestMark))
|
||||
|
||||
return eta
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user