-
Notifications
You must be signed in to change notification settings - Fork 218
refactor: rewrite the queue to make context aware #896
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
base: main
Are you sure you want to change the base?
Conversation
ring.go
Outdated
n := &r.store[atomic.AddUint32(&r.write, 1)&r.mask] | ||
n.c1.L.Lock() | ||
for n.mark != 0 { | ||
if ctxCh := ctx.Done(); ctxCh != nil { | ||
select { | ||
case <-ctxCh: | ||
n.c1.L.Unlock() | ||
n.c1.Signal() | ||
return nil, ctx.Err() | ||
default: | ||
} | ||
} | ||
n.c1.Wait() |
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.
Hi @proost, thanks! I think we are close, but 2 things:
- We should find a way to make the condition variable context aware,
n.c1.Wait(ctx)
, instead of a precheck. A precheck has already been done at the beginning of thepipe.Do()
. - Since we did
atomic.AddUint32(&r.write, 1)
, ther.write
has been incremented, and we may leave the correspondingr.store
slot empty if thectx
is errored. Do we handle the case correctly?
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.
We should find a way to make the condition variable context aware, n.c1.Wait(ctx), instead of a precheck. A precheck has already been done at the beginning of the pipe.Do().
I knew that point. I already said this PR doesn't solve the issue completely. This PR mitigates overhead when buffer is full and some requests are already canceled or timeout. Do you want solve problem completely? If then i need some time. because bigger code change is needed.
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 know you know, but since we have already done a precheck at the beginning of pipe.Do()
, a second precheck in the ring doesn't really help much. However, you did a great job on changing the ring interface. 👍
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 know you know, but since we have already done a precheck at the beginning of pipe.Do(), a second precheck in the ring doesn't really help much.
I'm not sure, but issue i mentioned, looks like happening when after pipe.Do()
, so it might helpful the situation.
Regardless of second precheckiong, complete solution is needed I think.
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 rewrite the queue.
tiny improvement about the issue
This PR doesn't solve above issue. To solve the issue, I think rewriting ring buffer is needed. But That's quite huge.
This PR improves two things.
I think this tiny improvement is helpful for very rare situation, that buffer is full and lots of requests are waiting other requests.