Closed nsentinel closed 3 years ago
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
Author: | nsentinel |
---|---|
Assignees: | - |
Labels: | `area-System.Net.Sockets`, `untriaged` |
Milestone: | - |
I can't think of a reason.
Are you running into this limit today? I'd recommend using async instead, as select()
will be incredibly inefficient in many scenarios with that number of sockets.
Thanks for the answer.
I hit the limit while rewriting the async version of our code to get more fine-grained control.
A server capable of serving 250k+ connections unexpectedly stopped at 65k. The limitation can be overcome by splitting the socket list into chunks before the API call.
I try to make one dispatcher thread with Socket.Select()
once per 200ms (when workers are idle) and worker threads (2 per core) to process received data.
I know about memory inefficiency (constant copy and remove sockets to/from the list) but the call rate is pretty low.
Are there other things to consider?
Interesting. I can see it being usable in some specific scenario like that. @antonfirsov @geoffkizer can you think of any reason for a limit here?
We're unlikely to invest in this change ourselves without more customers asking for it, but I don't think we'd reject a PR to raise the limit if were accompanied with appropriate tests.
I ran some additional tests under full load and concluded that you are right: select
is too inefficient to use, even with a low call rate.
In the end, I decided to stop using it.
We can close this ticket. It seems to me that the reasons for the limitation in 65536
sockets lie in inefficiency of use (modification of the list consume too much CPU and memory), and not in any restrictions.
It seems that it makes sense to mention this in the documentation, and it is not necessary to remove the restriction.
select is too inefficient to use, even with a low call rate.
I think this is the main issue.
I think it would be fine to increase the limit here, but in practice it's not really viable to use select this way.
Thanks for following up! Closing this now.
Can you please tell me what are the reasons behind limiting the number of requested sockets to
65535
for API Socket.Select():I found this limitation existed in the classic
.NET
: Here and moved toCore
and cross-platform sockets as is: HereThere is no mention of the limitation in the documentation.
The Windows implementation is based on the select function API (winsock2.h)
There is no mention of limitations in the documentation and if you study the SDK, they are also not obvious:
select
definition: Herefd_set
definition: Hereu_int
definition: HereThere is also document: Maximum Number of Sockets Supported
Exact implementation in
Windows Sockets Pal Layer
also has no implied limits: HereThe Linux/Unix implementation is based on the Poll API
Original Unix select API was limited to
FD_SETSIZE
(1024
) which is also not the 16-bit limit.So, what are the reasons behind limiting the number of requested sockets?