Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@stephentoub
Copy link
Member

Port #32495 to release/2.2.

Minimize the work done inside the lock in order to reduce contention. This means we need to reacquire the lock if the connection isn't usable, but in the fast path case where the connection is usable, we remove the syscalls from being performed while holding the lock.

Related to https://github.com/dotnet/corefx/issues/31799

… of lock (dotnet#32495)

Minimize the work done inside the lock in order to reduce contention.  This means we need to reacquire the lock if the connection isn't usable, but in the fast path case where the connection is usable, we remove the syscalls from being performed while holding the lock.
@stephentoub stephentoub added the tenet-performance Performance related issue label Oct 2, 2018
@stephentoub stephentoub added this to the 2.2 milestone Oct 2, 2018
@stephentoub
Copy link
Member Author

Description

SocketsHttpHandler pools connections, and when it takes a connection from the pool, it checks to see whether the connection is still alive. That check is currently happening while a lock is held, which under heavy load and many short requests can result increased contention on the lock. This change moves that check to outside of the lock, so that in the fast path / common case, the lock is held for a very short period of time.

Customer Impact

For microservices where many ASP.NET requests in turn make many HttpClient calls to other services, the contention can result in significantly reduced throughput than is otherwise possible. The benchmark results shown in #32495 (comment) highlight this impact.

Regression?

No

Risk

This code path is critical to SocketsHttpHandler, used in the processing of all requests, so a mistake here could be impactful. But the change itself is minimal: it moves some checks from inside the lock to outside the lock. The net result is that for the common case, we still take the lock once, but we hold it for a much shorter period of time. In the less common case where we were able to grab a connection but then discover after releasing the lock and doing these checks that the connection is no longer valid (e.g. the server closed it after a timeout), we end up needing to loop around and take the lock again, for a small increase in cost on the uncommon path.

@danmoseley danmoseley added the Servicing-consider Issue for next servicing release review label Oct 2, 2018
Copy link

@Eilon Eilon left a comment

Choose a reason for hiding this comment

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

I approve for 2.2, though I don't know the code.

@stephentoub
Copy link
Member Author

The Windows failure is an unrelated pipelines test: ReadAsyncCompletesIfFlushAsyncCanceledMidFlush.

@dotnet-bot test Outerloop Windows x64 Debug Build please

@stephentoub
Copy link
Member Author

cc: @geoffkizer

@jamshedd
Copy link
Member

jamshedd commented Oct 2, 2018

Approved for 2.2.

@jamshedd jamshedd added Servicing-approved-2.2 and removed Servicing-consider Issue for next servicing release review labels Oct 2, 2018
@stephentoub
Copy link
Member Author

The Outerloop Windows failures are unrelated:

@danmoseley
Copy link
Member

@stephentoub you can hit merge when CI is green (or effectively so)

@jamshedd jamshedd added Servicing-approved Approved for servicing release and removed Servicing-approved-2.2 labels Oct 2, 2018
@stephentoub stephentoub merged commit 7cddd8e into dotnet:release/2.2 Oct 2, 2018
@stephentoub stephentoub deleted the port32495 branch October 2, 2018 18:59
@stephentoub
Copy link
Member Author

Thanks

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

Labels

Servicing-approved Approved for servicing release tenet-performance Performance related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants