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

Exponential Backoff for ByteFIFO #15724

Merged
merged 8 commits into from
May 8, 2021
24 changes: 21 additions & 3 deletions modules/queue/queue_bytefifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ func (q *ByteFIFOQueue) Run(atShutdown, atTerminate func(context.Context, func()
}

func (q *ByteFIFOQueue) readToChan() {
backOffTime := time.Millisecond * 100
maxBackOffTime := time.Second * 3
backOff := func() time.Duration {
backOffTime += backOffTime / 2
if backOffTime > maxBackOffTime {
backOffTime = maxBackOffTime
}
return backOffTime
}
doBackOff := func() {
select {
case <-q.closed:
case <-time.After(backOff()):
}
}

for {
select {
case <-q.closed:
Expand All @@ -126,21 +142,23 @@ func (q *ByteFIFOQueue) readToChan() {
if err != nil {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
q.lock.Unlock()
log.Error("%s: %s Error on Pop: %v", q.typ, q.name, err)
time.Sleep(time.Millisecond * 100)
doBackOff()
continue
}

if len(bs) == 0 {
q.lock.Unlock()
time.Sleep(time.Millisecond * 100)
doBackOff()
continue
}

backOffTime = time.Millisecond * 100

data, err := unmarshalAs(bs, q.exemplar)
if err != nil {
log.Error("%s: %s Failed to unmarshal with error: %v", q.typ, q.name, err)
q.lock.Unlock()
time.Sleep(time.Millisecond * 100)
doBackOff()
continue
}

Expand Down