Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pool-ng #230

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

Draft
seanmonstar wants to merge 5 commits into master
base: master
Choose a base branch
Loading
from pool-ng
Draft

pool-ng #230

seanmonstar wants to merge 5 commits into master from pool-ng

Conversation

@seanmonstar
Copy link
Member

@seanmonstar seanmonstar commented Sep 16, 2025

Just a combined pull request for generating docs previews and some CI testing, look at the separate PRs for the individual pieces.

This comment was marked as outdated.

2 similar comments

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Member Author

/rustdoc-preview

Copy link

📝 Rustdoc preview for this PR: View docs

Copy link
Member Author

/rustdoc-preview

Copy link

📝 Rustdoc preview for this PR: View docs

Copy link

@sjcobb2022 sjcobb2022 left a comment

Choose a reason for hiding this comment

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

Looking great overall. Will test in some crates later on in the week

use http_body_util::Empty;
use hyper::Request;
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use hyper_util::client::pool;
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

nit: rename file to client_pool


let mut p = pool::Cache::new(http1).build();

let mut c = p.call(http::Uri::from_static("http://hyper.rs")).await?;
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

nit: use consistent uri for all calls.

let req = Request::builder()
.uri(url)
.body(Empty::<bytes::Bytes>::new())?;
async fn send_nego() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

nit: send_negotiate


for _ in 0..5 {
let mut c = svc
.call(http::Uri::from_static("http://localhost:3000"))
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

change to hyper.rs (or keep consistent with all other tests)

Comment on lines +3 to +9
//! The map isn't a typical `Service`, but rather stand-alone type that can map
//! requests to a key and service factory. This is because the service is more
//! of a router, and cannot determine which inner service to check for
//! backpressure since it's not know until the request is made.
//!
//! The map implementation allows customization of extracting a key, and how to
//! construct a MakeService for that key.
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

Potential rewrite:

This map is not a traditional Service; instead, it is a standalone type that allows users to associate incoming keys with service factories. For each request, a key is extracted and used to select or construct a corresponding service.

Because this service acts more like a router, it cannot determine which inner service to check for backpressure ahead of time; the appropriate service is only known once a request has been received.

let mut pool = super::Map::builder().keys(|_| "a").values(|_| "b").build();
pool.service(&"hello");
}
}
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

 #[test]
 fn it_returns_same_service_for_same_key() {
 let mut pool = Map::builder()
 .keys(|s: &&str| *s)
 .values(|_| {
 String::from("service")
 })
 .build();
 let service1 = pool.service(&"foo") as *const String;
 let service2 = pool.service(&"foo") as *const String;
 // Should be the same pointer.
 assert_eq!(service1, service2);
 }
 #[test]
 fn it_returns_different_service_for_different_keys() {
 let mut pool = Map::builder()
 .keys(|s: &&str| *s)
 .values(|s| format!("service-for-{}", s))
 .build();
 let service1 = pool.service(&"foo") as *const String;
 let service2 = pool.service(&"bar") as *const String;
 // Should NOT be the same pointer (different key/service)
 assert_ne!(service1, service2);
 // Optionally, check the actual value
 assert_eq!(pool.service(&"foo"), "service-for-foo");
 assert_eq!(pool.service(&"bar"), "service-for-bar");
 }

Comment on lines +3 to +8
//! The singleton pool combines a MakeService that should only produce a single
//! active connection. It can bundle all concurrent calls to it, so that only
//! one connection is made. All calls to the singleton will return a clone of
//! the inner service once established.
//!
//! This fits the HTTP/2 case well.
Copy link

@sjcobb2022 sjcobb2022 Oct 13, 2025

Choose a reason for hiding this comment

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

Take it or leave it:

The singleton pool manages a MakeService that should only produce a single active connection.

/// Provide a closure that extracts a pool key for the destination.
pub fn keys<K, KK>(self, keyer: K) -> Builder<Dst, K, S>
where
K: Fn(&Dst) -> KK,
Copy link

@sjcobb2022 sjcobb2022 Oct 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

Taking by reference here makes making extracting some types of keys quite hard

I think take a type Dst that implement clone would be better, and clone the type for mapping.

This way we don't need to deal with yucky schenarios like the following:

 let mut map = hyper_util::client::pool::map::Map::builder::<Uri>()
 .keys(|uri| uri.scheme()) // lifetime may not live long enough
 .values(|_| ())
 .build();

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

Reviewers

1 more reviewer

@sjcobb2022 sjcobb2022 sjcobb2022 left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /