Skip to content
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

flexible timeouts #1840

Merged
merged 155 commits into from Sep 3, 2018
Merged

flexible timeouts #1840

merged 155 commits into from Sep 3, 2018

Conversation

kazuho
Copy link
Member

@kazuho kazuho commented Aug 30, 2018

Until now, H2O's timeout handling is based on the assumption that there would be many delayed callbacks that share a small number of fixed "intervals", which has been true for HTTP. For example, all the idle connections refer to a single "interval" called "keepalive timeout."

However, the inflexibility is starting to bite us. For example, mruby's sleep function sets an arbitrary amount of milliseconds. QUIC also breaks the assumption; every connection has different RTT, and we need to set timers based on RTTs.

This PR switches the timeout mechanism used by evloop to "timer wheel", as well as changing that of the libuv binding to directly use uv_timer. For more information about timer wheel, see https://lwn.net/Articles/152436/.

Changes to the API:

Previously, we had two objects related to timeout handling. h2o_timeout_entry_t was the callback object. h2o_timeout_t was an anchor that contained a linked list of h2o_timeout_entry_ts that shared the same amount of delay.

The PR replaces the two with one type called h2o_timer_t. It is a callback object that can be assigned an arbitrary amount of delay.

/**
 * the callback
 */
typedef void (*h2o_timer_cb)(h2o_timer_t *timer);
/**
 * initializes a timer object (in inactive state)
 */
void h2o_timer_init(h2o_timer_t *timer, h2o_timer_cb cb);
/**
 * activates a timer object for which the callback will be invoked after `delay_ticks` milliseconds.
 */
void h2o_timer_link(h2o_loop_t *loop, uint64_t delay_ticks, h2o_timer_t *timer);
/**
 * returns if the timer is linked (i.e. activated)
 */
int h2o_timer_is_linked(h2o_timer_t *timer);
/**
 * cancels a timer (does nothing unless linked)
 */
void h2o_timer_unlink(h2o_timer_t *timer);

Grant Zhang and others added 30 commits September 25, 2017 21:47
- Add h2o_timeout_val_t structure to differentiate set/unset
- Rename h2o_timerwheel_* to h2o_timeout_*
We can fetch the values directly from globalconf
Instead of renaming `h2o_timeout_entry_t` to `h2o_timeout_t` (a type that no longer exists with the PR), the commit introduces
`h2o_timer` while eliminating `h2o_timeout_` entirely.

The new timeout mechanism is called "h2o_timer" throughout libh2o. For evloop, "h2o_timerwheel" is used *internally*.
@kazuho kazuho merged commit 097f073 into master Sep 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants