-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix buffer_drain_concurrency
not doing anything.
#14545
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -569,10 +569,32 @@ func (sb *shardBuffer) drain(q []*entry, err error) { | |
sb.timeoutThread.stop() | ||
|
||
start := sb.timeNow() | ||
// TODO(mberlin): Parallelize the drain by pumping the data through a channel. | ||
|
||
// Parallelize the drain by pumping the data through a channel. | ||
entryChan := make(chan *entry, len(q)) | ||
|
||
parallelism := min(bufferDrainConcurrency, len(q)) | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(parallelism) | ||
|
||
for i := 0; i < parallelism; i++ { | ||
go func() { | ||
for _, e := range q { | ||
sb.unblockAndWait(e, err, true /* releaseSlot */, true /* blockingWait */) | ||
} | ||
|
||
wg.Done() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}() | ||
} | ||
|
||
for _, e := range q { | ||
sb.unblockAndWait(e, err, true /* releaseSlot */, true /* blockingWait */) | ||
entryChan <- e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To elaborate: |
||
} | ||
|
||
close(entryChan) | ||
wg.Wait() | ||
Comment on lines
+574
to
+596
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to only pump the entries through the channel if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think this is an important optimization. We need a legacy codepath for when |
||
|
||
d := sb.timeNow().Sub(start) | ||
log.Infof("Draining finished for shard: %s Took: %v for: %d requests.", topoproto.KeyspaceShardString(sb.keyspace, sb.shard), d, len(q)) | ||
requestsDrained.Add(sb.statsKey, int64(len(q))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to make the channel buffered? 🤔 I think it should be fine to not have it buffered, but I'm not 100% sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be buffered, definitely not buffered as
len(q)
because that's a lot of underlying memory being allocated!