-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Expose server support for http2 keep-alive #474
Comments
I think this proposal seems reasonable 👍 |
Thanks! I'll prepare a PR with the changes as soon as I can. Do you think it is worth implement this as a cargo feature? --- a/tonic/Cargo.toml
+++ b/tonic/Cargo.toml
@@ -36,6 +36,7 @@ transport = [
tls = ["transport", "tokio-rustls"]
tls-roots = ["tls", "rustls-native-certs"]
prost = ["prost1", "prost-derive"]
+server-http2-keepalive = ["transport", "hyper/runtime"]
# [[bench]]
# name = "bench_main" |
@codermobster I don't think it's necessary to feature-gate this. It is also not necessary to add hyper's runtime feature flag. Why do you suggest to only support Anyway, I was playing with these settings, both in the client and server but I don't see any change in behavior, do you?. Maybe my expectations are off but when sniffing the traffic I detect no changes no matter which settings I use. |
Ok, deal.
Indeed, it's enabled by default. 👍
Sure, I guess I assumed that defaulting to hyper's setting of 20 seconds would be good enough. Furthermore, since http2_keep_alive_timeout does not take an
You got me! I totally took hyper for granted here and failed to find any open issues in github related to it. Tried to
5 seconds keepalive timeout and 20 seconds keep alive interval# some output has been elided
# the two following packets are still output after initiating the connection
17:56:10.541558 IP6 localhost.50051 > localhost.csccredir: Flags [P.], seq 61:124, ack 395, win 512, options [nop,nop,TS val 3578121404 ecr 3578121402], length 63
17:56:10.541571 IP6 localhost.csccredir > localhost.50051: Flags [.], ack 124, win 512, options [nop,nop,TS val 3578121404 ecr 3578121404], length 0
17:56:30.543874 IP6 localhost.50051 > localhost.csccredir: Flags [P.], seq 124:141, ack 395, win 512, options [nop,nop,TS val 3578141406 ecr 3578121404], length 17
17:56:30.543901 IP6 localhost.csccredir > localhost.50051: Flags [.], ack 141, win 512, options [nop,nop,TS val 3578141406 ecr 3578141406], length 0
# ... eliding some more The second batch of packets comes exactly 20 seconds after the first. 5 seconds keepalive timeout and 30 seconds keep alive interval# some output has been elided
# the two following packets are still output after initiating the connection
18:02:32.863479 IP6 localhost.50051 > localhost.43986: Flags [P.], seq 61:124, ack 395, win 512, options [nop,nop,TS val 3578503726 ecr 3578503724], length 63
18:02:32.863493 IP6 localhost.43986 > localhost.50051: Flags [.], ack 124, win 512, options [nop,nop,TS val 3578503726 ecr 3578503726], length 0
18:03:02.864626 IP6 localhost.50051 > localhost.43986: Flags [P.], seq 124:141, ack 395, win 512, options [nop,nop,TS val 3578533727 ecr 3578503726], length 17
18:03:02.864735 IP6 localhost.43986 > localhost.50051: Flags [.], ack 141, win 512, options [nop,nop,TS val 3578533727 ecr 3578533727], length 0
# ... eliding some more The second batch of packets comes exactly 30 seconds after the first. 20 seconds keepalive timeout and 10 seconds keep alive interval# some output has been elided
# the two following packets are still output after initiating the connection
18:10:44.883423 IP6 localhost.50051 > localhost.48110: Flags [P.], seq 61:124, ack 395, win 512, options [nop,nop,TS val 3578995746 ecr 3578995744], length 63
18:10:44.883436 IP6 localhost.48110 > localhost.50051: Flags [.], ack 124, win 512, options [nop,nop,TS val 3578995746 ecr 3578995746], length 0
18:10:54.885248 IP6 localhost.50051 > localhost.48110: Flags [P.], seq 124:141, ack 395, win 512, options [nop,nop,TS val 3579005747 ecr 3578995746], length 17
18:10:54.885270 IP6 localhost.48110 > localhost.50051: Flags [.], ack 141, win 512, options [nop,nop,TS val 3579005747 ecr 3579005747], length 0
# ... eliding some more The second batch of packets comes exactly 10 seconds after the first. ConcludingThe above is surely not 100% conclusive, but it seems:
Thanks @alce ! I'll prepare an issue in hyper with this info and link it here (credits to you of course!) |
Yeah, that's what I saw too. I would expect: Keeping hyper's default timeout seems fine to me. |
I've opened a PR in hyper to address this issue: hyperium/hyper#2315 |
Please correct me if I'm wrong, but I'm guessing the adequate approach now is to wait for a new version of hyper to be released (containing the fix) and have tonic depend on it, before going forward with a pull request here, right? |
@pdcalado We don't need to wait for hyper, we could go ahead with this change as soon as you are ready. However, there won't be a new tonic release until there is a new hyper release and these settings won't do anything until then, of course. |
Adds two methods to `transport::server::Server` for setting HTTP2 server keepalive interval and timeout as exposed by `hyper::server::Builder`. Fixes hyperium#474
Feature Request
Crates
tonic
Motivation
From what I understood from #307, HTTP2 keep alive support was exposed only to the client (unless I missed some way of doing so for the server).
However
hyper
also supports setting the keep alive interval and timeout for the server.My motivation for this enhancement is well described here, which I quote:
Proposal
I suggest that we only support setting
http2_keep_alive_interval
, with something along the lines of:This proposal leaves
http2_keep_alive_timeout
to be whicheverhyper
defaults to (currently 20 seconds).Note that the code above has not been compiled or tested, I'm happy to submit a PR if you guys think this change is worth it.
The main drawback I see is that the
runtime
feature ofhyper
must be enabled forhyper::server::Builder::http2_keep_alive_interval
to be used (link).Alternatives
None that I can think of, but I welcome any suggestions :D
Note
Thanks in advance for your help and thank you for the great work on tonic, hats off!
The text was updated successfully, but these errors were encountered: