-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Do event's timeout take priority over the event in the libevent adapter? #1286
Comments
I also believe I have seen signs that libevent prioritize timeouts, and possibly its due to that it calls timeout_process and the callback (with EV_TIMEOUT) through event_active_nolock before handling active events in event_process_active. If we use priority queues and have multiple clients connected using the same event base, wouldn't there be a risk of that one or many heavy loaded client(s) could starve out a failing client? The failing client might never get its timeout due to the new prioritization and we would never reconnect. |
I agree with your comment. For example, when managing connections to many nodes (such as in hiredis-cluster) with a single event_base, this may occur. Depending on how the client is used, this might not be an issue, but we should avoid setting priorities in general situations. Alternatively, would it be possible to mitigate the issue by separating ev into ev_io and ev_timer without setting any priorities? It seems that the I might be mistaken, but if I register the I/O event (ev_io) and the timeout event (ev_timer) separately, will ev_io be added at the head of the active queue, followed by ev_timer? In the current implementation, the activated callback of EV_READ is deleted in timeout_process, resulting in only EV_TIMEOUT being triggered.
|
Hello, hiredis team,
We are using the async context from hiredis-cluster to connect to a Redis Cluster, and I have a question regarding the behavior of the libevent adapter.
Let's assume a scenario where the libevent adapter is used and the execution of the event loop is delayed due to a high system load or any heavy handlers. Even if the Redis response is already available to be read by the time the event loop runs, the timeout event is always fired. In such cases, it seems better to be able to read the already received response and execute the appropriate callback instead of resulting in a timeout.
In
libevent.h
, the timeout is specified withevent_add(e->ev, tv);
, but when bothEV_READ
/EV_WRITE
and the timeout become active at the same time, there is no defined priority. In my environment, the timeout is always prioritized (?).hiredis/adapters/libevent.h
Line 103 in 4ece9a0
Here are simple reproduction test codes. To keep things simple, the event loop is executed one iteration at a time using
event_base_loop(base, EVLOOP_ONCE)
, and a sleep is used to intentionally delay the execution of the event loop.Is this timeout behavior considered a specification or is it a bug?
For example, applying a patch like the one below to libevent.h resolved this issue. In the patch, IO and timer events are registered separately, and priorities are set so that IO events are triggered before timer events. And, we probably need to call
event_base_priority_init(base, 2);
to init priorities of the event base.Thank you so much.
The text was updated successfully, but these errors were encountered: