-
Notifications
You must be signed in to change notification settings - Fork 904
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
Provide a way to limit max number of requests and max connection age for client #3267
Conversation
…for client Motivation: A long connection can cause load imbalance between servers if clients do not use client-side balance. The clients which use L4 load balancers keep a connection to a server. The traffic could be rebalanced by closing connections periodically or after N requests. A max connection age for server-side was added by line#2747. However max connection age for client and max number of requests for server and client have not implemented yet. Related: line#203 line#2741 line#2747 Modifications: - Add `maxNumRequests` to `ServerBuilder`, `ClientFactoryBuilder` and `Flags` - Send `GOAWAY` or `Connection: close` by server-side - Remove from channel pool and close a connection or send `GOAWAY` by client-side - Add `maxConnnectionAge{Millis}` to `ClientFactoryBuilder` and `Flags` - Keep track of requests count by KeepAliveHandler to determine a connection is needed to close - Remove some fields, derived from ClientFatory, in `HttpChannelPool` and pass `ClientFactory` to `HttpSessionHandler` for reducing object size and simplicity. - Add `MaxConnectionAgeExceededTask` to close an expired connection. Result: - You can now set a maximum allowed number of requests for a connection. ```java // For server Server.builder() // A connection will be closed after serving 10000 requests. .maxNumRequests(10000); // For client ClientFactory.builder() // A connection will be closed after fully receiving 2000th requests. .maxNumRequests(2000) ``` - You can now set a maximum allowed connection age for a connection on client-side. ```java // A connection will be closed in 10 seconds after the connection is established. ClientFactory.builder() .maxConnnectionAgeMillis(10000) ``` - Fixes line#203
c38c54a
to
ccf2dd6
Compare
Codecov Report
@@ Coverage Diff @@
## master #3267 +/- ##
============================================
- Coverage 74.10% 74.02% -0.08%
- Complexity 13015 13085 +70
============================================
Files 1136 1143 +7
Lines 49276 49661 +385
Branches 6256 6303 +47
============================================
+ Hits 36515 36761 +246
- Misses 9546 9657 +111
- Partials 3215 3243 +28
Continue to review full report at Codecov.
|
core/src/main/java/com/linecorp/armeria/client/ClientFactoryOptions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/HttpResponseDecoder.java
Outdated
Show resolved
Hide resolved
3d3f8ff
to
3c17cae
Compare
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientFactoryBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientFactoryOptions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientFactoryOptions.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientFactoryOptions.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/KeepAliveHandlerUtil.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏👏👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎉 🎉
Motivation:
A long connection can cause load imbalance between servers if clients do not use client-side balance.
Because L4 load balancers keep a client connection to a server.
The traffic could be rebalanced by closing connections periodically or after N requests.
A max connection age for server-side was added by #2747.
However max connection age for client and max number of requests for server and client have not implemented yet.
Related: #203 #2741 #2747
Modifications:
maxNumRequestsPerConnection
toServerBuilder
,ClientFactoryBuilder
andFlags
GOAWAY
orConnection: close
by server-sideGOAWAY
by client-sidemaxConnnectionAge{Millis}
toClientFactoryBuilder
andFlags
HttpChannelPool
andpass
ClientFactory
toHttpSessionHandler
for reducing object size and simplicity.MaxConnectionAgeExceededTask
to close an expired connection.Result:
Co-authored-by: julie-kim julie.kim@linecorp.com