-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Simplify goroutine setup for async task requests #4924
Simplify goroutine setup for async task requests #4924
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Ignored Deployments
|
🟢 CI successful 🟢Thanks |
Not quite what I meant. You're seeing a slowdown because the channel is unbuffered: writers must wait for an available reader. While the first request is pending, no one can write to the channel. So, the goal is to read from the channel as fast as possible and not block reading on IO. Pseudocode of one way to do it: func start() {
firstRequestDone := make(chan interface{})
go func() {
pending := []*request{}
startedFirstRequest := false
FirstRequest:
for {
select {
case <-firstRequestDone:
for _, req := range pending {
go doReq(req)
}
break FirstRequest
case req <- requestsChannel:
if startedFirstRequest {
pending = append(pending, req)
} else {
startedFirstRequest = true
doFirstReq(req)
}
}
}
for _, req := range requestsChannel {
go doReq(req)
}
}()
} In this case, you have a single reader that never blocks. When it gets the first request, it starts it. While the first request is in flight, it buffers subsequent requests. When the first request completes, it fires off the buffered requests and switches to reading and immediately firing off requests |
0507314
to
4c2a970
Compare
// listen for new requests coming in | ||
case req := <-c.requests: | ||
if req == nil { | ||
continue |
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 added this check to prevent a bunch of nil
s getting added to the pending
slice, but I'm not sure why/how nil messages are being passed to this channel. My guess is it has something to do with the for
loop, but I'm not sure.
@gsoltis thanks! this mostly worked. Only thing I don't understand he requests channel receives a ton of I also don't quite get the |
Going to merge this into the base PR for a holistic look and put in any questions there. |
0159de9
into
mehulkar/turbo-916-runs-send-task-summaries-as-tasks-finish
This change works, but I see that the total execution time jumps from ~500ms to ~2s though (both FULL TURBO). I can share the test I'm using (in front).
The execution time shouldn't change by much, because execution is closed off before the
wg.Wait()
, so I don't think this diff is the best either