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

Improve Unix synchronous socket perf#5472

Merged
ericeil merged 7 commits into
dotnet:masterfrom
ericeil:SyncPerf
Feb 4, 2016
Merged

Improve Unix synchronous socket perf#5472
ericeil merged 7 commits into
dotnet:masterfrom
ericeil:SyncPerf

Conversation

@ericeil

@ericeil ericeil commented Jan 15, 2016

Copy link
Copy Markdown
Contributor

Synchronous operations on sockets are currently always emulated in terms of async/non-blocking operations. This has quite a lot of run-time overhead, due to extra system calls, context switches, etc.

With this change we keep the socket in "blocking" mode until the user requests non-blocking mode or initiates an asynchronous operation. The result is that a socket that only ever experiences synchronous operations will not have the overhead of emulating sync over async.

@stephentoub

Copy link
Copy Markdown
Member

Thanks for doing this, @ericeil.

Before I review, just so I understand, we still follow the existing sync-over-async code paths and have extra expenses like the allocation of the MRES here (

using (var @event = new ManualResetEventSlim())
), but the operation will actually always complete synchronously and thus we always take the fast path out, right? Or have I misunderstood?

@ericeil

ericeil commented Jan 15, 2016

Copy link
Copy Markdown
Contributor Author

@stephentoub, that's right.

@ericeil

ericeil commented Jan 16, 2016

Copy link
Copy Markdown
Contributor Author

Looks like there's a test hanging. I'll look at it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we should either change the native signature to not even allow setting back to blocking, or potentially just add an assert to the native function that verifies we're only ever setting it to non-blocking and not to blocking.

@stephentoub

Copy link
Copy Markdown
Member

LGTM, other than the test failure.

@stephentoub

Copy link
Copy Markdown
Member

Did you figure out the cause of the hang?

@ericeil

ericeil commented Jan 22, 2016

Copy link
Copy Markdown
Contributor Author

I think I just figured out the hang. It looks like we expect close(fd) to unblock a blocking call to accept(fd). That doesn't seem to be happening. I'd expect to have the same issue with all the other blocking calls as well. This may need more thought....

@ericeil

ericeil commented Jan 29, 2016

Copy link
Copy Markdown
Contributor Author

The Unix test failures should be fixed by #5790. The Windows test failures are due to my fix for the previous Unix test failures, in 26e5670; I'll need to figure out what to do about those.

… begin an async operation. For blocking sockets that never start an async operation, this avoids the overhead of emulating blocking semantics on top of a non-blocking socket.
@ericeil

ericeil commented Feb 4, 2016

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Innerloop CentOS7.1 Debug Build and Test

@ericeil

ericeil commented Feb 4, 2016

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Innerloop CentOS7.1 Release Build and Test

ericeil added a commit that referenced this pull request Feb 4, 2016
Improve Unix synchronous socket perf
@ericeil
ericeil merged commit 14d29e7 into dotnet:master Feb 4, 2016
@ericeil
ericeil deleted the SyncPerf branch February 9, 2016 20:47
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
@karelz karelz added the os-linux Linux OS (any supported distro) label Mar 8, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Improve Unix synchronous socket perf

Commit migrated from dotnet/corefx@14d29e7
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net os-linux Linux OS (any supported distro)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants