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

Send an HTTP/2 PING frame on an idle connection #2409

Merged
merged 45 commits into from
Mar 9, 2020

Conversation

sivaalli
Copy link
Contributor

@sivaalli sivaalli commented Jan 18, 2020

Related: #2388 #1263
Motivation:

It is possible that an HTTP/2 connection has no traffic at all even if there are active streams. In such a case, Armeria client or server could send some PING frames to keep the connection alive or to detect TCP-level failure quickly.

Modifications:

  • Add http2PingTimeoutMillis and useHttp2PingWhenNoActiveStreams option

Result:


@trustin @anuraaga Please let me know what do you think of this.

Previous conversation: #2388
Issue: #1263

Since we thought of sending PING when idle (regardless of if there are open streams or not) , I leveraged IdlePingHandler.

~~This is not complete yet, but wanted to get overall feedback on the approach. ~~
The continuation for this would be is to add IdleStateHandler which emits IdleStateEvent for http2 channels and use HttpServerIdleTimeoutHandler for http1.1 channels.

  1. Add properties in Flags to let user change pingTimeoutInMillis
  2. Added feature for client and server.
  3. Added tests for Http2KeepAliveHandler

@trustin
Copy link
Member

trustin commented Jan 18, 2020

That was fast! Let me take a look soon. 🙇‍♂️

@codecov
Copy link

codecov bot commented Jan 18, 2020

Codecov Report

Merging #2409 into master will decrease coverage by 0.04%.
The diff coverage is 62.55%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2409      +/-   ##
============================================
- Coverage     73.63%   73.59%   -0.05%     
- Complexity    10865    10906      +41     
============================================
  Files           952      953       +1     
  Lines         41581    41795     +214     
  Branches       5219     5240      +21     
============================================
+ Hits          30620    30757     +137     
- Misses         8288     8341      +53     
- Partials       2673     2697      +24
Impacted Files Coverage Δ Complexity Δ
.../linecorp/armeria/client/ClientFactoryBuilder.java 65% <0%> (-4.34%) 40 <0> (ø)
.../linecorp/armeria/client/ClientFactoryOptions.java 78.57% <100%> (+1.07%) 27 <2> (+2) ⬆️
...m/linecorp/armeria/client/ClientFactoryOption.java 71.64% <100%> (+1.8%) 7 <0> (ø) ⬇️
...p/armeria/server/HttpServerIdleTimeoutHandler.java 75% <100%> (ø) 3 <1> (ø) ⬇️
...p/armeria/client/HttpClientIdleTimeoutHandler.java 100% <100%> (ø) 2 <1> (ø) ⬇️
...ava/com/linecorp/armeria/server/ServerBuilder.java 79.5% <20%> (-1.7%) 105 <0> (ø)
...p/armeria/client/Http2ClientConnectionHandler.java 58.62% <40%> (-21.38%) 7 <2> (+2)
.../linecorp/armeria/client/Http2ResponseDecoder.java 62.01% <41.66%> (-1.01%) 34 <7> (+1)
...m/linecorp/armeria/server/Http2RequestDecoder.java 68.79% <46.15%> (-2.53%) 28 <14> (+1)
...rp/armeria/internal/common/IdleTimeoutHandler.java 70.58% <57.14%> (-9.42%) 6 <4> (+2)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7c0eaa...5b786c6. Read the comment docs.

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work all in all! Are you going to implement this on the client-side as well?

@sivaalli
Copy link
Contributor Author

sivaalli commented Jan 18, 2020

Nice work all in all! Are you going to implement this on the client-side as well?

Yes Trustin, I will implement for client side as well. Also, will make all the suggested corrections. Thanks for your quick review 🙇

@sivaalli
Copy link
Contributor Author

@trustin Can you please skim through when you get some spare time. I have used AbstractHttp2ConnectionHandler.handlerAdded() to change state of IdleTimeoutHandler from http1 to http2. If this looks, I will proceed further. 🙇

@sivaalli
Copy link
Contributor Author

I hope this is ready for full review now. Changing to Ready for review.

@sivaalli sivaalli marked this pull request as ready for review January 22, 2020 22:57
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @sivaalli! Left some nits only. 👍

@trustin trustin added this to the 0.98.0 milestone Jan 23, 2020
@trustin trustin modified the milestones: 0.98.0, 1.0.0 Feb 7, 2020
@sivaalli sivaalli force-pushed the http_ping_second_iteration branch from b5c5786 to 878d7b9 Compare February 17, 2020 14:22
@trustin
Copy link
Member

trustin commented Feb 20, 2020

@sivaalli How's this PR going? Anything we can help?

@sivaalli
Copy link
Contributor Author

@sivaalli How's this PR going? Anything we can help?

@trustin I've resumed working on this. As discussed, I will make changes

  1. To PING when idle regardless of open streams.
  2. To PING only when there are any open streams.

And let user decide whats best for their use case.

The implementation mostly looks like the one in grpc. I will push code for review when I have working code. Thanks for your patience :)

@sivaalli sivaalli changed the title Http ping second iteration [WIP] Http ping second iteration Feb 25, 2020
@sivaalli sivaalli force-pushed the http_ping_second_iteration branch from 6e501ae to d3a320a Compare February 25, 2020 03:24
@sivaalli
Copy link
Contributor Author

The tests are incomplete, but feel free to skim if possible. Will work on tests and then will formally request a full review. :)

@sivaalli
Copy link
Contributor Author

@anuraaga @ikhoon @trustin Could you guys please review this and let me know if changes are needed. Thanks.

@sivaalli sivaalli force-pushed the http_ping_second_iteration branch from b13946c to 6836434 Compare March 5, 2020 22:42
Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! @sivaalli. Thanks!

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Great thanks to @sivaalli 🙇‍♂️

@trustin trustin modified the milestones: 1.0.0, 0.99.0 Mar 9, 2020
@trustin trustin changed the title Http ping second iteration Send an HTTP/2 PING frame on an idle connection Mar 9, 2020
@trustin trustin merged commit b1bb733 into line:master Mar 9, 2020
@trustin
Copy link
Member

trustin commented Mar 9, 2020

I really appreciate your hard work on this, @sivaalli ❤️

fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Related: line#2388 line#1263
Motivation:

It is possible that an HTTP/2 connection has no traffic at all even if there are active streams. In such a case, Armeria client or server could send some PING frames to keep the connection alive or to detect TCP-level failure quickly.

Modifications:

- Add `http2PingTimeoutMillis` and `useHttp2PingWhenNoActiveStreams` option

Result:
- Fixes line#1263

Co-authored-by: Trustin Lee <[email protected]>
Co-authored-by: Anuraag Agrawal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to send a PING frame periodically for HTTP/2 connections
5 participants