Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Architecture

Tags:

c#

.net

sockets

Hopefully two simple questions relating to creating a server application:

  • Is there a theoretical/practical limit on the number of simultaneous sockets that can be open? Ignoring the resources required to process the data once it has arrived! If its of relevance I am targeting the .net framework
  • Should each connection be run in a separate thread that's permanently assigned to it, or should use of a Thread Pool be made? The dedicated thread approach seems simpler, but it seems odd to have 100+ threads running it once. Is this acceptable practice?

Any advice is greatly appreciated Venatu

like image 231
Venatu Avatar asked Mar 04 '26 21:03

Venatu


2 Answers

You may find the following answer useful. It illustrates how to write a scalable TCP server using the .NET thread pool and asynchronous sockets methods (BeginAccept/EndAccept and BeginReceive/EndReceive).

This being said it is rarely a good idea to write its own server when you could use one of the numerous WCF bindings (or even write custom ones) and benefit from the full power of the WCF infrastructure. It will probably scale better than every custom written server.

like image 136
Darin Dimitrov Avatar answered Mar 06 '26 11:03

Darin Dimitrov


There are practical limits, yes. However, you will most likely run out of resources to handle the load long before you reach them. CPU, or memory are more likely to be exhausted before number of connections.

For maximum scalability, you don't want a seperate thread per connection, but rather you would use an Asynchronous model that only uses threads when servicing active (as in receiving or sending data) connections.

like image 32
Erik Funkenbusch Avatar answered Mar 06 '26 10:03

Erik Funkenbusch