Skip to content

Comments

Issue at most one connection attempt per request#67114

Merged
MihaZupan merged 5 commits intodotnet:mainfrom
MihaZupan:http-connectionpool-differentinitialrequest
Mar 28, 2022
Merged

Issue at most one connection attempt per request#67114
MihaZupan merged 5 commits intodotnet:mainfrom
MihaZupan:http-connectionpool-differentinitialrequest

Conversation

@MihaZupan
Copy link
Member

This PR changes how we associate connection attempts to requests:

Instead of always associating with the first request in the queue, each request in the queue will be associated with at most one connection attempt.

If the connection ends up establishing, it will always process the associated request first, before looking at the rest of the queue.
If it fails, it will fail only the associated request, as long as it wasn't already processed by a different connection.

This means that we may now have completed requests amongst the canceled and pending ones in the queue.
We are relying on other connections to prune the head of the queue, similar to #66992.
This is something we could improve in the future (immediately remove such entries to reduce memory usage).

To track which requests already have an associated connection attempt, the RequestQueue keeps an extra head pointer (_attemptedConnectionsOffset). This pointer tracks the first request without an associated connection attempt.

@MihaZupan MihaZupan added this to the 7.0.0 milestone Mar 24, 2022
@MihaZupan MihaZupan requested review from a team and stephentoub March 24, 2022 20:03
@ghost
Copy link

ghost commented Mar 24, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR changes how we associate connection attempts to requests:

Instead of always associating with the first request in the queue, each request in the queue will be associated with at most one connection attempt.

If the connection ends up establishing, it will always process the associated request first, before looking at the rest of the queue.
If it fails, it will fail only the associated request, as long as it wasn't already processed by a different connection.

This means that we may now have completed requests amongst the canceled and pending ones in the queue.
We are relying on other connections to prune the head of the queue, similar to #66992.
This is something we could improve in the future (immediately remove such entries to reduce memory usage).

To track which requests already have an associated connection attempt, the RequestQueue keeps an extra head pointer (_attemptedConnectionsOffset). This pointer tracks the first request without an associated connection attempt.

Author: MihaZupan
Assignees: -
Labels:

area-System.Net.Http

Milestone: 7.0.0

@MihaZupan MihaZupan closed this Mar 25, 2022
@MihaZupan MihaZupan reopened this Mar 25, 2022
@MihaZupan
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Task.Run(() => AddHttp11ConnectionAsync(request));
RequestQueueItem<HttpConnection> queueItem = _http11RequestQueue.PeekNextRequestForConnectionAttempt();

Task.Run(() => AddHttp11ConnectionAsync(queueItem));
Copy link
Member

@stephentoub stephentoub Mar 25, 2022

Choose a reason for hiding this comment

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

This change is also avoiding a closure allocation on the fast path that seems to have snuck into CheckForHttp11ConnectionInjection.

@MihaZupan MihaZupan merged commit a10c1bc into dotnet:main Mar 28, 2022
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
* Issue at most one connection attempt per request

* Drop the Try- from PeekNextRequestForConnectionAttempt

* Add test

* PR feedback

* Entry => QueueItem
@ghost ghost locked as resolved and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants