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

Add connection-limiting pool #253

Merged
merged 24 commits into from
Feb 27, 2020
Merged

Add connection-limiting pool #253

merged 24 commits into from
Feb 27, 2020

Conversation

trowski
Copy link
Member

@trowski trowski commented Jan 15, 2020

Not sure on the name, suggestions welcome.

Should we deprecate LimitedConnectionPool or rename it (with an alias of the old name) to SingleStreamConnectionPool or leave it as-is?

Closes #252.

Copy link
Contributor

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

thanks for the clarification

src/Connection/FiniteConnectionPool.php Outdated Show resolved Hide resolved
@kelunik
Copy link
Member

kelunik commented Jan 15, 2020

Why SingleStreamConnectionPool? It isn't a single stream, but the concurrency you specify in the semaphore.

@trowski
Copy link
Member Author

trowski commented Jan 16, 2020

@kelunik Yes, was thinking of a mutex not a semaphore. I renamed it to StreamLimitingConnectionPool instead. I can revert that commit if we just want to keep the original name.

@kelunik
Copy link
Member

kelunik commented Jan 21, 2020

@nicolas-grekas Could you clarify which limit you actually intend to use? I guess you want something like 6 connections for HTTP/1 and one connection for HTTP/2?

@nicolas-grekas
Copy link
Contributor

Yes correct. Using up to 6 connections on h2 would work too, but I don't know which algo should select opening a new connection vs a new stream. Dunno also how curl does it.

@kelunik
Copy link
Member

kelunik commented Jan 21, 2020

But isn't the limit also there to limit concurrent requests, which is then basically no longer the case for HTTP/2 connections?

@nicolas-grekas
Copy link
Contributor

Yes that's true. Yet browsers still open several connections to work around TCP throttling, which is the drawback of h2, the reason why h3 exists.

@trowski
Copy link
Member Author

trowski commented Jan 21, 2020

Pushed a commit that separates the HTTP/2 and HTTP/1.x connection limits in the pool. Default is 6 HTTP/1.x and 1 HTTP/2. Does this make sense for most use-cases?

Copy link
Contributor

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks! 6 & 1 work for me but I'm wondering: let's say there is only one single maximum for both h1 and h2. Is there a way to race for "new connection is ready" vs "existing connection becomes available" and have this logic decide which stream is used for the next request? It would work for both h1 and h2 and might be the most performant, WDYT?

src/Connection/FiniteConnectionPool.php Outdated Show resolved Hide resolved
src/Connection/FiniteConnectionPool.php Outdated Show resolved Hide resolved
@kelunik
Copy link
Member

kelunik commented Jan 24, 2020

Is there a way to race for "new connection is ready" vs "existing connection becomes available" and have this logic decide which stream is used for the next request?

Yes, that should be possible.

@nicolas-grekas
Copy link
Contributor

I hope my last comment didn't block progress on this one :)

@trowski
Copy link
Member Author

trowski commented Feb 7, 2020

@nicolas-grekas Maybe a little. 😏

I have another branch, fallback-to-existing-connection that extends this PR, what do you think? Can you give it a try? If that approach works well, I'll merge it into this PR.

Naming is so hard… still not sure if I like this one either.
Why duplicate code when I can effectively remove the limits!
@nicolas-grekas
Copy link
Contributor

nicolas-grekas commented Feb 14, 2020

I just checked out this PR and I confirm it fixes the perf issue, which means connections are now much better reused.
Since Symfony has a single setting for the number of maximum connections to open, I'm creating the pool using:
$pool = CountLimitingConnectionPool::byAuthority($maxHostConnections, $maxHostConnections, $factory);

I tried using 1 for the number of HTTP/2 connections but that changes nothing as far as perf is concerned on my use case (actually it's a bit slower).

I think there should be only one single maxHttpConnections argument here too.

Reduced delay in tests for faster execution.
@nicolas-grekas
Copy link
Contributor

PR updated on Symfony's side, now using a single $maxHostConnections setting, all green. Merge + tag pending, then we'll be able to merge on Symfony's side \o/

@kelunik kelunik merged commit 61570f2 into master Feb 27, 2020
@kelunik kelunik deleted the alternative-connection-pool branch February 27, 2020 20:10
@kelunik
Copy link
Member

kelunik commented Feb 27, 2020

@nicolas-grekas We're done. \o/

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

Successfully merging this pull request may close these issues.

LimitedConnectionPool limits concurrent requests instead of concurrent connections
3 participants