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

Revamp connection pool #1441

Merged
merged 4 commits into from
Nov 19, 2018
Merged

Revamp connection pool #1441

merged 4 commits into from
Nov 19, 2018

Conversation

trustin
Copy link
Member

@trustin trustin commented Nov 15, 2018

Related: #818

Motivation:

  • Unlike HTTP/1 connections, HTTP/2 connections do not need to be
    removed from the connection pool. We has slight loss of efficiency
    because we currently remove an HTTP/2 connection from the pool and
    add it back.
  • Current connection pool implementation has unnecessarily deep type
    hierarchy and high level of indirection which weren't very useful.
  • There's circular package dependency between armeria.client and
    armeria.client.pool which is undesirable.

Modifications:

  • Merged HttpSessionChannelFactory, KeyedChannelPool and
    DefaultKeyedChannelPool into HttpChannelPool.
    • Tuned the internal data structure of DefaultKeyedChannelPool.
      • PoolKey does not include SessionProtocol anymore. We keep
        separate Map for each SessionProtocol.
    • Improved the connection pool implementation so that the connections
      with the same session protocol are grouped together even if they
      were created from different URI schemes. For example, both h2c://
      and http:// can create h2c connections, but their connections
      were treated differently, but not anymore.
    • Removed unnecessary synchronization since all code in
      HttpChannelPool should be run in an event loop.
  • Replaced KeyedChannelPoolHandler and its related classes with
    ConnectionPoolListener et al.
    • We do not notify the listeners about acquisition and release because
      it has no meaning for HTTP/2 and it is more meaningful to retrieve
      such information from RequestLog. Let me know if you have a
      suggestions for more listener methods.

Result:

@codecov
Copy link

codecov bot commented Nov 15, 2018

Codecov Report

Merging #1441 into master will increase coverage by 0.13%.
The diff coverage is 74.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1441      +/-   ##
==========================================
+ Coverage   72.75%   72.88%   +0.13%     
==========================================
  Files         617      613       -4     
  Lines       26842    26750      -92     
  Branches     3246     3248       +2     
==========================================
- Hits        19528    19496      -32     
+ Misses       5599     5543      -56     
+ Partials     1715     1711       -4
Impacted Files Coverage Δ
.../java/com/linecorp/armeria/client/HttpSession.java 50% <ø> (ø) ⬆️
.../armeria/client/ConnectionPoolListenerWrapper.java 0% <0%> (ø)
.../linecorp/armeria/client/ClientFactoryBuilder.java 56.73% <100%> (ø) ⬆️
...inecorp/armeria/client/ConnectionPoolListener.java 100% <100%> (ø)
...om/linecorp/armeria/client/HttpSessionHandler.java 58.87% <100%> (ø) ⬆️
...ava/com/linecorp/armeria/client/PooledChannel.java 100% <100%> (ø)
...com/linecorp/armeria/client/HttpClientFactory.java 88.76% <100%> (+1.49%) ⬆️
.../armeria/client/ConnectionPoolListenerAdapter.java 100% <100%> (ø)
...a/com/linecorp/armeria/client/HttpChannelPool.java 70.61% <70.61%> (ø)
.../client/logging/ConnectionPoolLoggingListener.java 91.3% <91.3%> (ø)
... and 19 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 7798b0c...d73819b. Read the comment docs.

@trustin
Copy link
Member Author

trustin commented Nov 15, 2018

@inch772 You might want to review this pull request since 1) the connection pooling has been written by you initially and 2) you might be looking for a chance to exercise your coding skill!

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.

Great job~!

@trustin
Copy link
Member Author

trustin commented Nov 16, 2018

@anuraaga You may want to check this commit as well which got into after your approval 96fa6c3

@minwoox
Copy link
Member

minwoox commented Nov 16, 2018

LGTM again~!

@anuraaga
Copy link
Collaborator

LGTM

Related: line#818

Motivation:

- Unlike HTTP/1 connections, HTTP/2 connections do not need to be
  removed from the connection pool. We has slight loss of efficiency
  because we currently remove an HTTP/2 connection from the pool and
  add it back.
- Current connection pool implementation has unnecessarily deep type
  hierarchy and high level of indirection which weren't very useful.
- There's circular package dependency between `armeria.client` and
  `armeria.client.pool` which is undesirable.

Modifications:

- Merged `HttpSessionChannelFactory`, `KeyedChannelPool` and
  `DefaultKeyedChannelPool` into `HttpChannelPool`.
  - Tuned the internal data structure of `DefaultKeyedChannelPool`.
    - `PoolKey` does not include `SessionProtocol` anymore. We keep
      separate `Map` for each `SessionProtocol`.
  - Improved the connection pool implementation so that the connections
    with the same session protocol are grouped together even if they
    were created from different URI schemes. For example, both `h2c://`
    and `http://` can create `h2c` connections, but their connections
    were treated differently, but not anymore.
  - Removed unnecessary synchronization since all code in
    `HttpChannelPool` should be run in an event loop.
- Replaced `KeyedChannelPoolHandler` and its related classes with
  `ConnectionPoolListener` et al.
  - We do not notify the listeners about acquisition and release because
    it has no meaning for HTTP/2 and it is more meaningful to retrieve
    such information from `RequestLog`. Let me know if you have a
    suggestions for more listener methods.

Result:

- Fixes line#818
- Connection pool listener API has a breaking change.
Copy link
Contributor

@hyangtack hyangtack left a comment

Choose a reason for hiding this comment

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

LGTM :-)

@trustin trustin merged commit 8e20974 into line:master Nov 19, 2018
@trustin trustin deleted the fix_818 branch November 19, 2018 03:22
@trustin
Copy link
Member Author

trustin commented Nov 19, 2018

Thank you, reviewers!

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

Motivation:

- Unlike HTTP/1 connections, HTTP/2 connections do not need to be
  removed from the connection pool. We has slight loss of efficiency
  because we currently remove an HTTP/2 connection from the pool and
  add it back.
- Current connection pool implementation has unnecessarily deep type
  hierarchy and high level of indirection which weren't very useful.
- There's circular package dependency between `armeria.client` and
  `armeria.client.pool` which is undesirable.

Modifications:

- Merged `HttpSessionChannelFactory`, `KeyedChannelPool` and
  `DefaultKeyedChannelPool` into `HttpChannelPool`.
  - Tuned the internal data structure of `DefaultKeyedChannelPool`.
    - `PoolKey` does not include `SessionProtocol` anymore. We keep
      separate `Map` for each `SessionProtocol`.
  - Improved the connection pool implementation so that the connections
    with the same session protocol are grouped together even if they
    were created from different URI schemes. For example, both `h2c://`
    and `http://` can create `h2c` connections, but their connections
    were treated differently, but not anymore.
  - Removed unnecessary synchronization since all code in
    `HttpChannelPool` should be run in an event loop.
- Replaced `KeyedChannelPoolHandler` and its related classes with
  `ConnectionPoolListener` et al.
  - We do not notify the listeners about acquisition and release because
    it has no meaning for HTTP/2 and it is more meaningful to retrieve
    such information from `RequestLog`. Let me know if you have a
    suggestions for more listener methods.

Result:

- Fixes line#818
- Connection pool listener API has a breaking change.
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.

4 participants