TCP server max number of sockets

E

eran.yasso

Hi all,

I need to develop a TCP server which communicate with TCP clients.
There can be Tens of thousands client which the server should handle.
Is there any limit to the number of open connections in the server assuming my PC uses 8GBytes of RAM with Intel I7 CPU?

Does .Net limit the number of open connections?
What is the best server Architecture I should use?

Thanks for the help.
 
B

bradbury9

El martes, 26 de febrero de 2013 10:26:36 UTC+1, (e-mail address removed) escribió:
Hi all,



I need to develop a TCP server which communicate with TCP clients.

There can be Tens of thousands client which the server should handle.

Is there any limit to the number of open connections in the server assuming my PC uses 8GBytes of RAM with Intel I7 CPU?



Does .Net limit the number of open connections?

What is the best server Architecture I should use?



Thanks for the help.

..NET does not limit the number of connections. MS Windows (and other operative systems) does. Check this link http://smallvoid.com/article/winnt-tcpip-max-limit.html
 
B

bradbury9

El martes, 26 de febrero de 2013 13:15:48 UTC+1, (e-mail address removed) escribió:
Hi bradbury9,



Is there any C# sample which show a TCP server should be written in orderto support as much as possible connected clients at a time?



Thanks.

Personally I have never written a tcp server but the process should be pretty straightforward.

-Create a windows service that handles the incoming connections.
-When an incoming connection arrives dispatch it to another thread, maybe using async API (never used that API, but it is well documented and there are answers about taht topic in this newsgroup).

Maybe you should consider load balancing and creating a server farm
 
A

Arne Vajhøj

I need to develop a TCP server which communicate with TCP clients.
There can be Tens of thousands client which the server should handle.
Is there any limit to the number of open connections in the server assuming my PC uses 8GBytes of RAM with Intel I7 CPU?

Does .Net limit the number of open connections?

TCP/IP limits the number.

The operating system or TCP/IP stack limits the number.

..NET may or may not limit all or certain operations based on how it
interacts with the native API's. I have never heard about such limits,
but that does not prove that such does not exist.
What is the best server Architecture I should use?

Impossible to say with certainty based on so little information.

But as a rule of thumb:

1-500 clients : one thread per TCP connection [assuming a decent number
of CPU threads available]
501-5000 clients : fixed number of threads (much smaller than number
clients) handling all clients [.NET has rick API's for that]
5001- clients : switch to UDP

Arne
 
A

Arne Vajhøj

El martes, 26 de febrero de 2013 13:15:48 UTC+1, (e-mail address removed)
escribió:
Personally I have never written a tcp server but the process should
be pretty straightforward.

-Create a windows service that handles the incoming connections.
-When an incoming connection arrives dispatch it to another thread,
maybe using async API (never used that API, but it is well documented
and there are answers about taht topic in this newsgroup).

A thread per client will not work with so many clients.

Another paradigm is needed.

The various async API's are the .NET way of doing it.
Maybe you should consider load balancing and creating a server farm

If the servers need to share state between clients, then it will
also complicate the application quite a bit.

Arne
 
B

bradbury9

El miércoles, 27 de febrero de 2013 03:49:44 UTC+1, Arne Vajhøj escribió:
A thread per client will not work with so many clients.



Another paradigm is needed.



The various async API's are the .NET way of doing it.






If the servers need to share state between clients, then it will

also complicate the application quite a bit.



Arne

Totally agree on the state issue, but the OP wants tons of connections AND use TCP so not an easy task without some sort of load balancing if tens of thousands connections are needed. Besides a server farm makes easy a contingency plan.
 
A

Arne Vajhøj

[...]
5001- clients : switch to UDP

I'm skeptical that this is a good idea.

The only person I know personally first-hand who has written a large-scale
server architecture from scratch in .NET, he supports hundreds of thousands
of simultaneous clients with TCP using the async APIs (the first version).

There are plenty of examples using UDP out there. Documented examples.
UDP won't decrease network overhead. It probably will even increase it.

It will decrease network overhead. But that was not the point.
It
for sure _will_ increase code complexity, along with design,
implementation, and maintenance costs.

It uses the same event driven model as TCP without a thread per
connection, so no change for that part.

Some reliability features missing in UDP may need to be added, but
that will be rather trivial compared to all the other challenges
in a solution of that magnitude.
It _might_ reduce local resource
usage, depending on platform, but at the same time will likely increase the
required numbers of re-transmits for any given datagram, due to the lack of
per-client buffering (again, depending on platform...it's theoretically
possible for a network driver to maintain per-client buffering even for
UDP, but I'm not aware of any such implementation).

UDP is good for certain things. But I'm aware of no valid evidence to
suggest it's the right approach for increasing the number of clients a
server can support.

????

Getting rid of the connection concept do avoid problems with max
connections rather effectively.
Frankly, the fact that HTTP is designed around TCP and that HTTP servers
are able to handle well above your "5000" number seems proof enough to me
that there's no need to change protocols just to support larger numbers of
clients. There _are_ web servers out there successfully dealing with far
larger numbers than that.

I think you have misunderstood how HTTP works. HTTP connects, interact
and disconnect. Using keep-alive enables multiple interactions between
connect and disconnect.

Therefore N users accessing the web server does not mean
N concurrent TCP connections.

You can serve maybe 25000 users with just 2500 TCP connections.

Furthermore at least the most used web server (Apache) let connections
wait in the backlog queue until it is ready to process the request. I
suspect that IIS/ASP.NET does something similar.

HTTP and a socket client/server solution are simply very different
in how they do things, so you can not conclude much from HTTP.
Yes, you need a machine configured to handle the number of connections you
want to support. But ensuring that is way easier to do than writing a
reliable network i/o component on top of UDP.

UDP is generally appropriate when your particular need doesn't require
reliable delivery of data; otherwise, TCP is the right solution. I will
grant that it's a common mistake to choose UDP because one thinks it's
faster, more efficient, etc. but in practice those things turn out to
generally not be true, nor worth the trade-off of an incorrect UDP-based
implementation that screws up your data.

What is needed for reliability depends on the problem domain.

And if there are high requirements, then there are well-tested
libraries available. I don't know if such exist for .NET though.

Arne
 
A

Arne Vajhøj

On Tue, 26 Feb 2013 21:42:55 -0500, Arne Vajhøj wrote:

[...]
5001- clients : switch to UDP

I'm skeptical that this is a good idea.

The only person I know personally first-hand who has written a large-scale
server architecture from scratch in .NET, he supports hundreds of thousands
of simultaneous clients with TCP using the async APIs (the first version).

There are plenty of examples using UDP out there. Documented examples.

That's not the point. I never said one couldn't do it using UDP.

You were skeptical that it was a good idea.
The point is that there are examples of TCP servers that work just fine
with just as many simultaneous connections.

Link ?
There's no reason to believe UDP will decrease network overhead. Note that
by "overhead" I am referring to the cost of the network i/o relative to the
whole program (server). UDP itself may have less overhead for a given
amount of data (depending on usage patterns), but the same basic amount of
information (including data to identify the connection being handled) will
still need to move across the network, costing the server the same basic
overhead in network i/o.

Not every network usage need all the features provides by TCP.

And if they don't need all the features they don't need all the
overhead.

And if they don't need the overhead they will be faster.

That is pretty simple logic.
???

TCP does not require a thread per connection. In fact, as has already been
made clear,

Yes. Including by me.

But that is not what the above says.

It says that UDP use the same event driven model as TCP without a thread
per connection - unlike TCP with a thread per connection.
Writing a reliable implementation on top of UDP is not trivial at all. Lots
of programmers over the years have gotten, and will continue to get, it
wrong.

That depends on the context/requirements.

In some cases it is very trivial. In some cases it is not.
[...]
UDP is good for certain things. But I'm aware of no valid evidence to
suggest it's the right approach for increasing the number of clients a
server can support.

????

Getting rid of the connection concept do avoid problems with max
connections rather effectively.
No.

Yes.

First, you are talking about solving a problem that does not exist. TCP
can handle way more than 5000 concurrent connections.

It can. But it start to come with cost.
In any case, it simply shifts the cost from the network stack to the
program itself. If the program is going to depend on a connection-oriented
paradigm, that paradigm has to be implemented somewhere.

You can either let TCP handle it for you, or you can do it yourself. But it
has to live somewhere.

A connection oriented paradigm requires something, but it does not
necessarily require the same overhead as TCP.
The bottom line is that existing TCP-based servers handle far greater
numbers of simultaneous connections than the 5000 you suggest for UDP.
Beyond that, there's simply no real-world indication that UDP is needed to
go beyond that 5000 threshold you suggest, nor is UDP an appropriate
solution when reliable delivery of data is needed.

Not correct.

A non reliable protocol at transport layer does not mean unreliable
at the application level.

And here may be good reasons to put the reliability at the
application level instead of the transport level.

In fact there does not seem to be any correlation between
application level reliability and transport level reliability.

HTTP, FTP, SMTP, telnet does not seem more reliable than
DNS, NTP and NFS to me.

Arne
 
A

Arne Vajhøj

Yes. Why reinvent the wheel for no good reason? That it can be done is no
good reason, in and of itself.

Well - it was not without reason. It was to avoid having thousands or
tens of thousands of TCP contexts.
Completely different issue. Don't change the subject.

????

It is the core of the debate.
We are talking about a scenario where the reliability of TCP is needed.

No. We are talking about OP's question. He did not require the
reliability of TCP in his question.
If
it weren't, one wouldn't/shouldn't be using TCP in the first place.

Which is exactly my point.

But unlike you I am not convinced that everybody asking a question
about TCP have carefully considered the UDP option.
???

First you say that you didn't write that TCP requires a thread per
connection. Then you compare UDP to using "TCP with a thread per
connection".

You are making no sense.

I think you are just slow to get the point.

TCP with a thread per client is a convenient programming model.

TCP or UDP without a thread per client is slightly more work,
but it is the same model for TCP and UDP.
There's no need to switch to UDP just to get away from having one thread
per connection. So why even mention it? It has nothing to do with whether
UDP is or is not better than TCP for handling large numbers of connections
(or clients, in the UDP case).

See above.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top