-
Notifications
You must be signed in to change notification settings - Fork 921
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 close a connection when exceeding the maximum age on server-side #2747
Conversation
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/Http2ServerConnectionHandler.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/HttpServerPipelineConfigurator.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ServerMaxConnectionAgeTest.java
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ServerMaxConnectionAgeTest.java
Outdated
Show resolved
Hide resolved
Motivation: Sometimes users might want to disconnect an active connection after a certain period of time. This is useful when balance loads with a L4 load balancer which not understand HTTP2 connection. By closing connections periodically, new connections are able to spread to other servers. Modifications: - Add `defaultServerMaxConnectionAgeMillis` flag. This option is disabled by default. - Add `maxConnectionAge{Millis} to `ServerBuilder`. - Record `CONNECTION_START_TIME_NANO` when a channel is initialized. - Disconnect a connection after exceeding maxConnectionAge by sending: - "Connection: close" for HTTP/1 - GOAWAY frame for HTTP/2 - Fix a bug where `channel.close()` throws NullPointerException when idle timeout is set to 0 Result: - You can now send `GOAWAY` frame with HTTP/2 and `Connection: close` with HTTP/1 for an old connection on server-side.
17a68a0
to
ab7e489
Compare
core/src/main/java/com/linecorp/armeria/server/HttpServerHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/HttpServerHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerHttp1ObjectEncoder.java
Outdated
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ServerMaxConnectionAgeTest.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #2747 +/- ##
============================================
+ Coverage 72.70% 72.80% +0.09%
- Complexity 11756 11867 +111
============================================
Files 1032 1042 +10
Lines 45875 46134 +259
Branches 5720 5757 +37
============================================
+ Hits 33355 33588 +233
+ Misses 9599 9596 -3
- Partials 2921 2950 +29 Continue to review full report at Codecov.
|
core/src/main/java/com/linecorp/armeria/internal/common/KeepAliveHandler.java
Outdated
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ServerMaxConnectionAgeTest.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.
Excellent work, @ikhoon 👍
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.
Nice work, @ikhoon!
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
… server-side (line#2747) Motivation: Sometimes users might want to disconnect an active connection after a certain period of time. This is useful when balance loads with an L4 load balancer which not understand HTTP2 connection. By closing connections periodically, new connections are able to spread to other servers. Modifications: - Add `defaultServerMaxConnectionAgeMillis` flag. This option is disabled by default. - Add `maxConnectionAge{Millis} to `ServerBuilder`. - Record `CONNECTION_START_TIME_NANO` when a channel is initialized. - Disconnect a connection after exceeding `maxConnectionAge` by sending: - "Connection: close" for HTTP/1 - GOAWAY frame for HTTP/2 - Fix a bug where `channel.close()` throws NullPointerException when idle timeout is set to 0 Result: - You can now disconnect an old connection.
…for client Motivation: A long connection can cause load imbalance between servers if clients does not use client-side balance. The clients will use L4 loadbalancer which keeps 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 requeets for server and client have not impletemented 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 receving 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
…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
…for client (#3267) 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: - Add `maxNumRequestsPerConnection` 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. .maxNumRequestsPerConnection(10000); // For client ClientFactory.builder() // A connection will be closed after fully receiving the response of 2000th requests. .maxNumRequestsPerConnection(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 #203 Co-authored-by: julie-kim <julie.kim@linecorp.com>
Motivation:
Sometimes users might want to disconnect an active connection after a certain period of time.
This is useful when balance loads with an L4 load balancer which not understand HTTP2 connection.
By closing connections periodically, new connections are able to spread to other servers.
Modifications:
defaultServerMaxConnectionAgeMillis
flag. This option is disabled by default.maxConnectionAge{Millis} to
ServerBuilder`.CONNECTION_START_TIME_NANO
when a channel is initialized.maxConnectionAge
by sending:channel.close()
throws NullPointerException when idle timeout is set to 0Result: