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

Provide a way to limit max number of requests and max connection age for client #3267

Merged
merged 12 commits into from
Jan 27, 2021

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Jan 7, 2021

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.
    // 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.
    // A connection will be closed in 10 seconds after the connection is established.
    ClientFactory.builder()
                 .maxConnnectionAgeMillis(10000);
  • Fixes Automatic disconnection after handling N requests #203

Co-authored-by: julie-kim julie.kim@linecorp.com

@ikhoon ikhoon added this to the 1.4.0 milestone Jan 7, 2021
…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
@codecov
Copy link

codecov bot commented Jan 7, 2021

Codecov Report

Merging #3267 (cc55c0c) into master (7fdbddb) will decrease coverage by 0.07%.
The diff coverage is 82.32%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...ecorp/armeria/client/ClientHttp2ObjectEncoder.java 37.83% <0.00%> (ø) 8.00 <0.00> (+2.00)
...rp/armeria/client/Http1ClientKeepAliveHandler.java 100.00% <ø> (ø) 6.00 <0.00> (ø)
...rp/armeria/client/Http2ClientKeepAliveHandler.java 100.00% <ø> (ø) 2.00 <0.00> (ø)
...orp/armeria/internal/common/HttpObjectEncoder.java 63.63% <ø> (ø) 10.00 <0.00> (ø)
...rp/armeria/server/Http2ServerKeepAliveHandler.java 75.00% <ø> (ø) 3.00 <0.00> (ø)
...ecorp/armeria/server/ServerHttp2ObjectEncoder.java 79.41% <33.33%> (-5.89%) 15.00 <1.00> (-1.00)
.../linecorp/armeria/client/Http2ResponseDecoder.java 68.61% <50.00%> (-2.16%) 44.00 <7.00> (+4.00) ⬇️
...armeria/internal/common/Http1KeepAliveHandler.java 50.00% <50.00%> (ø) 1.00 <1.00> (?)
...ecorp/armeria/server/ServerHttp1ObjectEncoder.java 83.33% <50.00%> (-3.21%) 21.00 <0.00> (+1.00) ⬇️
.../linecorp/armeria/client/Http1ResponseDecoder.java 66.66% <66.66%> (-0.22%) 43.00 <6.00> (-1.00)
... and 57 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 7fdbddb...cc55c0c. 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.

👏👏👏

Copy link
Member

@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.

🎉 🎉 🎉

@trustin trustin merged commit ca79592 into line:master Jan 27, 2021
@ikhoon ikhoon deleted the max-requests-limit branch January 27, 2021 12:55
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.

Automatic disconnection after handling N requests
3 participants