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

How to use Socket to write high-performance sending data in concurrent scenarios? #44182

Closed
NMSAzulX opened this issue Nov 3, 2020 · 5 comments

Comments

@NMSAzulX
Copy link

NMSAzulX commented Nov 3, 2020

If I want to write a high-performance Socket communication program, should I use mmap and socket.sendfile?
How to use Socket to write high-performance sending data in concurrent scenarios?

@NMSAzulX NMSAzulX added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 3, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net.Sockets untriaged New issue has not been triaged by the area owner labels Nov 3, 2020
@ghost
Copy link

ghost commented Nov 3, 2020

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

@wfurt
Copy link
Member

wfurt commented Nov 3, 2020

There may not be simple answer to the simple question. I strongly recommend to build prototypes using different strategies and measuring perf - if you really care. Also API performing well on one platform may show different characteristic on different OS (or version) even if we try to minimize such behavior.
Since you mentioned sendfile, that is certainly not a bad choice since on most OSes this is performed by kernel itself e.g. without all the overhead of user space application.

@wfurt wfurt removed api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged New issue has not been triaged by the area owner labels Nov 3, 2020
@wfurt wfurt added this to the 6.0.0 milestone Nov 3, 2020
@NMSAzulX
Copy link
Author

NMSAzulX commented Nov 3, 2020

@wfurt Thank you for your answer. I'm trying the "sendfile" solution, and I'm also following .NET 5 System.Net.Connections API. I don't know how to make the right choice between them. I am learning this example: https://github.com/davidfowl/CommunityStandUpNet5/blob/master/APIPlayground/Program.cs, and this is not a very simple example. I am confused, this should not be easy to use in a short period of time. :)

@antonfirsov
Copy link
Member

antonfirsov commented Nov 3, 2020

@NMSAzulX System.Net.Connections has been removed from the final version of .NET 5, for explanation see #41648 (comment).

I would use plain sockets. What's most performant also depends on the application. I'm not sure if SendFile is the best approach when it comes to sending small chunks of data, but might worth a try. You may also get some inspiration from Kestrel's socket transport layer, but it's definitely a very complex code:
https://github.com/dotnet/aspnetcore/tree/ad94d41a7f786bd11e1a3e1f599feeaac147610a/src/Servers/Kestrel/Transport.Sockets/src/Internal

@NMSAzulX
Copy link
Author

NMSAzulX commented Nov 3, 2020

@antonfirsov Oh! Thank you very much. Through your and wfurt's description, I think these feature will have an answer in .NET 6.0. I had to use another approach, such as Kestrel or httpClient. :)

@NMSAzulX NMSAzulX closed this as completed Nov 4, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants