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

Use SetFileCompletionNotificationModes on Windows #476

Closed
alexcrichton opened this issue Sep 26, 2016 · 1 comment
Closed

Use SetFileCompletionNotificationModes on Windows #476

alexcrichton opened this issue Sep 26, 2016 · 1 comment
Labels
windows Related to the Windows OS.

Comments

@alexcrichton
Copy link
Contributor

I/O operations on Windows tend to have the ability to "complete immediately". For example something like read_overlapped returns io::Result<bool> where Ok(false) means the operation is pending and Ok(true) means the operation completed immediately. These correspond to the underlying primitives on Windows (with various error codes).

Unfortunately, though, "completes immediately" means that by default a completion message is enqueued on the completion port. That means that if we were to service the read immediately we'd have to arrange for that later completion message to get ignored, which isn't currently easy to do. This means that although the read finished immediately we return WouldBlock and let the trip through the event loop complete the read at a later date.

As you can imagine, this seems like it can definitely be a performance hit! Thankfully Windows has an API for this, SetFileCompletionNotificationModes, which will cause a completion status to not get enqueued if an operation finishes immediately. We should use this on Windows at least for TCP/UDP read/write to help throughput.

Some caveats:

  • The API is not supported on Windows XP
  • There's apparently bugs in the WSARecv implementation which libuv works around at least. I think this is only for UDP, though?
  • We should benchmark the actual gains here to make sure it's what we expect
@carllerche
Copy link
Member

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Related to the Windows OS.
Projects
None yet
Development

No branches or pull requests

2 participants