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

Improve memory of producer retry queue #396

Merged
merged 1 commit into from
Apr 5, 2015
Merged
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
24 changes: 14 additions & 10 deletions async_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/eapache/go-resiliency/breaker"
"github.com/eapache/queue"
)

func forceFlushThreshold() int {
Expand Down Expand Up @@ -592,19 +593,21 @@ func (p *asyncProducer) flusher(broker *Broker, input chan []*ProducerMessage) {
// effectively a "bridge" between the flushers and the topicDispatcher in order to avoid deadlock
// based on https://godoc.org/github.com/eapache/channels#InfiniteChannel
func (p *asyncProducer) retryHandler() {
var buf []*ProducerMessage
var msg *ProducerMessage
refs := 0
shuttingDown := false
var (
msg *ProducerMessage
buf = queue.New()
refs = 0
shuttingDown = false
)

for {
if len(buf) == 0 {
if buf.Length() == 0 {
msg = <-p.retries
} else {
select {
case msg = <-p.retries:
case p.input <- buf[0]:
buf = buf[1:]
case p.input <- buf.Peek().(*ProducerMessage):
buf.Remove()
continue
}
}
Expand All @@ -622,13 +625,14 @@ func (p *asyncProducer) retryHandler() {
break
}
} else {
buf = append(buf, msg)
buf.Add(msg)
}
}

close(p.retries)
for i := range buf {
p.input <- buf[i]
for buf.Length() != 0 {
p.input <- buf.Peek().(*ProducerMessage)
buf.Remove()
}
close(p.input)
}
Expand Down