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
Proposal provide support for notifying the latest added waiter (LIFO) for the Notify interface #6506
Comments
I've worked on a PR - still on WIP and without tests - which shows a possible implementation for addressing this issue pfreixes@1d20704. |
If we do this, it would most likely be a new |
I was thinking on this too, but since this Unless we are able to wire in somehow the the strategy used between the call to Also not sure if there is a place for use cases where WDYT? |
There are several reasons that I prefer
The point you make about forwarding notifications in drop is good. I'm not sure how I feel about this feature request given that. One could perhaps add a |
About your considerations:
Might be simpler, but seems to me quite subjective and in the end having the feeling that would be better to have a way for providing a LIFO strategy than having nothing.
Its a 4 bytes increase for a struct that at least for use cases like this one are just shared references to the same struct, which for this use cases having a 4 bytes increase in size is kinda negligible. Not sure about other use cases, but considering that Notify is kinda used for syncing different tasks, I would expect a very similar usage pattern.
I still prefer the option of configuring the strategy at the beginning, unless the points that you have raised are a deal breaker. |
I'm sorry, but if the API you are looking for is one with a I've actually considered introducing a |
So either we reach an implementation where we can expose just
Oks if Im understanding this, if we move the extra required 4 bytes payload as part of the state for waking up a waiter - still to be proven how doable it is - for telling the strategy used, implementations like this one should not get impacted. right? |
Yes, I don't want to go for the solution with a That said, I would prefer to get some input from @carllerche before we continue here. |
Ah nice let me take a look to this. |
If a waiter has been waiting for too long and you want to notify more recent waiters, wouldn't it be better to first notify the old waiters with an error or some signal telling them to error out? |
I guess that this is an expectation that should be managed by the caller. By for example limiting the time for processing a request, which if this request would be in waiting state for having its waiter associated waiting for getting a free DB connection, after a while and once reached the max time the waiter will be just removed without completing its task and not getting any resource. But this would need to happen regardless if the strategy for dequeuing waiters would be FIFO or LIFO. Going back to the reason to why LIFO, when you have resources enough FIFO vs LIFO will not make a difference, but when you have contention and there is no enough resources for processing all waiters (i.e DB connections), by giving priority to the one that have been waiting longer by giving resources to them would mean that the overall latency of such operation would be worst compared to the latency that you would get giving this opportunity to the one that have been waiting less. With a bit of luck the ones that would have been waiting longer, in case of a contention, will have the chance to fall into a higher latency percentile than the one that you could be using for measuring your SLO. |
I was trying to find some examples where LIFO is used for helping on the latency side, just found this use case from Netflix, where its claimed that:
|
I was referring to |
Is your feature request related to a problem? Please describe.
Current implementation of
notify_one
uses FIFO semantics for returning the oldest waiter added into the linked list. While it seems fair this does not play very well when the system is under a lot of pressure and for keeping high percentile statistics under the expected SLOs. By dequeuing the waiter that was waiting for a longer period of time there is higher chance of increasing the overall latency of the system, measured as for example with the percentile 99.Describe the solution you'd like
This could be mitigated by changing - or providing an altenative solution - the strategy, by dequeueing the latest waiter added (LIFO), which will make sure that we process the element that will have more chances to not hurt the latencies of our system, since was the one in the queue for a shorter period of time
Additional context
If you believe that this could be a good addition for Tokio I would love to provide a PR with the implementation for supporting the new strategy LIFO but still keeping the current implementation FIFO as the default one.
If so, I would also appreciate a some guidance on how we could change current interfaces for limiting the breaking changes as much as possible .
The text was updated successfully, but these errors were encountered: