Skip to content

Allow for generic Keys in connection pooling. #3064

Closed
@EItanya

Description

@EItanya

Is your feature request related to a problem? Please describe.
Currently I wish to use the hyper client for http2 connection pooling, however I need to be able to pool by specific metadata. Specifically the SourceIp/Identity.

However, currently the keys in the connection pooling code are limited to a very specific set of data, specifically the protocol and the authority:

pub(super) type Key = (http::uri::Scheme, http::uri::Authority); //Arc<String>;

Describe the solution you'd like
I understand the the client code is built specifically around pooling with this metadata, but if we allowed the key to be generic, rather than that specific data, it would allow reuse of the pooling code for other client implementations.

I created a branch of hyper-utils where I tested this and mostly got it working, would love additional feedback. Here is a gist containing the pool code: https://gist.github.com/EItanya/61c4a2d67eb194e9891f7d54c2806d9d

The most important part is the addition of a second type argument to pool, namely the key type:

pub(super) struct Pool<T, K: Eq + Hash + Clone + Debug + Unpin> {
    // If the pool is disabled, this is None.
    inner: Option<Arc<Mutex<PoolInner<T, K>>>>,
}

Thereby allowing the caller of this code to decide how the connections should be pooled.

This would require very few changes on the part of the hyper client to implement as well.

Describe alternatives you've considered
The only other solution I can think of is writing it from scratch, or manually changing it heavily.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-clientArea: client.C-featureCategory: feature. This is adding a new feature.E-mediumEffort: medium. Some knowledge of how hyper internal works would be useful.K-hyper-utilCrate: hyper-util

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions