<p>When writing a custom server, what are the best practices or techniques to determine maximum number of users that can connect to the server at any given time?</p>

<p>I would assume that the capabilities of the computer hardware, network capacity, and server protocol would all be important factors.  </p>

<p>Also, do you think it is a good practice to limit the number of network connections to a certain maximum number of users? Or should the server not limit the number of network connections and let performance degrade until the response time is extremely high?</p>

[{'answer_id': 78437, 'author': 'Don Neufeld', 'author_id': 13097, 'author_profile': 'https://Stackoverflow.com/users/13097', 'pm_score': 3, 'selected': False, 'text': '<p>In general modern servers can handle very large numbers of concurrent connections.  I\'ve worked on systems having over 8,000 concurrently open TCP/IP sockets.</p>\n\n<p>You will need a high quality servicing interface to handle that kind of load, check out <a href="http://monkey.org/~provos/libevent/" rel="noreferrer">libevent</a> or <a href="http://software.schmorp.de/pkg/libev.html" rel="noreferrer">libev</a>.</p>\n'}, {'answer_id': 78454, 'author': 'zxcv', 'author_id': 9628, 'author_profile': 'https://Stackoverflow.com/users/9628', 'pm_score': 0, 'selected': False, 'text': '<p>One of the biggest setbacks in high concurrency connections is actually the routers involved. Home user oriented routers usually have a small NAT table, preventing the router from actually servicing the server the connections. </p>\n\n<p>Be sure to research your router/ network infrastructure setup just as well.</p>\n'}, {'answer_id': 78466, 'author': 'Svet', 'author_id': 8934, 'author_profile': 'https://Stackoverflow.com/users/8934', 'pm_score': 0, 'selected': False, 'text': "<p>I think you shouldn't limit the number of connections your server will allow - just catch and handle properly any exceptions that might occur when accepting and closing connections and you should be fine. You should leave that kind of lower level programming to the underlying OS layers - that way you can port your server easier etc. </p>\n"}, {'answer_id': 78467, 'author': 'William', 'author_id': 9193, 'author_profile': 'https://Stackoverflow.com/users/9193', 'pm_score': 0, 'selected': False, 'text': '<p>This really depends on your operating system.</p>\n\n<p>Different Unix flavors will support "unlimited" number of file handles / sockets others have high values like 32768.</p>\n\n<p>A typical user limit is 8192 but it can usually be set higher.</p>\n\n<p>I think windows is more limiting but the server version may have higher limits.</p>\n'}, {'answer_id': 78470, 'author': 'Michael Brown', 'author_id': 14359, 'author_profile': 'https://Stackoverflow.com/users/14359', 'pm_score': 2, 'selected': False, 'text': '<p>That is a good question and it definitely is situational. What is your computer? Do you have a 4 socket machine filled with Quad Core Xeons, 128 GB of RAM, and Fiber Channel Connectivity (like the pair of Dell R900s we just bought)? Or are you running on a p3 550 with 256 MB of RAM, and 56K modem? How much load does each connection place on your server? What kind of response is acceptible?</p>\n\n<p>These are the questions you need to answer. I guess the best way to find the answer is through load testing. Create a unit test of the expected (and maybe some unexpected) paths that your code will perform against your server. Find a load testing framework that will allow you to simulate 10, 100, 1000, 10000 users performing those tasks at the same time.</p>\n\n<p>That will tell you how many connections your computer can support.</p>\n\n<p>The great thing about the load/unit test scenario is that you can put in response time expectations in your unit tests and increase the load until you fall outside of your response time. If you have a requirement of supporting X number of Users with Y second response, you will be able to demonstrate it with your load tests.</p>\n'}, {'answer_id': 78578, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 4, 'selected': True, 'text': '<p>Dan Kegel put together a summary of techniques for handling large amounts of network connections from a single server, here: <a href="http://www.kegel.com/c10k.html" rel="noreferrer">http://www.kegel.com/c10k.html</a></p>\n'}]
['https://Stackoverflow.com/questions/78422', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10216/']