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

New abstractions for connection and connection pools. #6129

Open
ikhoon opened this issue Feb 26, 2025 · 0 comments
Open

New abstractions for connection and connection pools. #6129

ikhoon opened this issue Feb 26, 2025 · 0 comments

Comments

@ikhoon
Copy link
Contributor

ikhoon commented Feb 26, 2025

  • ConnectionPool.maxNumConnections() will limit the maximum connection more intuitively than maxNumEventLoopsPerEndpoint.
    • For HTTP/2, maxNumConnections() will default to 1 or 2.
    • For HTTP/1, Integer.MAX_VALUE can be the sensible default value.
    • The user will be able to set the desired number of connections through the connection pool more easily.
    • Devs may not have to explain maxNumEventLoopsPerEndpoint on Discord channels and how to control the maximum number of connections.
public interface ConnectionPool extends SafeCloseable {

  @Nullable
  Connection acquire(ClientRequestContext ctx);

  void release(Connection connection);

  void add(Connection connection);

  void remove(Connection connection);

  int maxNumConnections();
}

public class Connection {
  private SessionProtocol protocol;
  private Endpoint endpoint;
  private Channel channel;
  private EventLoop eventLoop;
}
  • LoadBalancer<Connection, ClientRequestContext> may be used to pick a connection in a connection pool.
    • A new LoadBalancer to pick a connection that has the least requests could be implemented later.
    ConnectionPool.builder()
                  .loadBalancerFactory(connections -> LoadBalancer.ofSticky(connections, ...))
                  .maxNumConnections(1)
                  ...
    ClientFactory.builder()
                 .http1ConnectionPoolFactory(... -> newConnectionPool())
                 .http2ConnectionPoolFactory(... -> newConnectionPool())
  • After an Endpoint is acquired, the Endpoint is used as a key to a ConnectionPool for the endpoint.
    Map<Endpoint, ConnectionPool> pools = new ConcurrentHashMap<>();
    ConnectionPool pool = pools.get(ctx.endpoint());
    Connection connection = pool.acquire(ctx);
    if (connection == null) {
      // create a new connection using Bootstrap and add it to the connection pool
    }

I will do more PoC on a separate branch and leave feedback on whether this proposal is possible without making significant changes to the current implementation.

Ref: #5779 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant