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

kgo: broadcast batch finishes in one big blast #878

Merged
merged 1 commit into from
Jan 20, 2025
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
17 changes: 11 additions & 6 deletions pkg/kgo/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ func (p *producer) promiseRecordBeforeBuf(pr promisedRec, err error) {
func (p *producer) finishPromises(b batchPromise) {
cl := p.cl
var more bool
var broadcast bool
defer func() {
if broadcast {
p.c.Broadcast()
}
}()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we validate this through a test?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's to validate? This is a change from doing a broadcast many times to doing it once -- the test is that things still work (which existing tests cover).

What can't really be tested is if this improves the problem you're running into.

Copy link

@StarpTech StarpTech Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me. I was able to verify the fix so I thought it can be verified as a test as well. A test could validate if producing is actually fast enough.

start:
p.promisesMu.Lock()
for i, pr := range b.recs {
Expand All @@ -558,7 +564,8 @@ start:
pr.ProducerID = b.pid
pr.ProducerEpoch = b.epoch
pr.Attrs = b.attrs
cl.finishRecordPromise(pr, b.err, b.beforeBuf)
recBroadcast := cl.finishRecordPromise(pr, b.err, b.beforeBuf)
broadcast = broadcast || recBroadcast
b.recs[i] = promisedRec{}
}
p.promisesMu.Unlock()
Expand All @@ -572,7 +579,7 @@ start:
}
}

func (cl *Client) finishRecordPromise(pr promisedRec, err error, beforeBuffering bool) {
func (cl *Client) finishRecordPromise(pr promisedRec, err error, beforeBuffering bool) (broadcast bool) {
p := &cl.producer

if p.hooks != nil && len(p.hooks.unbuffered) > 0 {
Expand All @@ -599,12 +606,10 @@ func (cl *Client) finishRecordPromise(pr promisedRec, err error, beforeBuffering
p.mu.Lock()
p.bufferedBytes -= userSize
p.bufferedRecords--
broadcast := p.blocked.Load() > 0 || p.bufferedRecords == 0 && p.flushing.Load() > 0
broadcast = p.blocked.Load() > 0 || p.bufferedRecords == 0 && p.flushing.Load() > 0
p.mu.Unlock()

if broadcast {
p.c.Broadcast()
}
return broadcast
}

// partitionRecord loads the partitions for a topic and produce to them. If
Expand Down
Loading