Skip to content

Handling large numbers of concurrent connections

zaphoyd edited this page Dec 10, 2011 · 2 revisions

File Descriptor Limits

Every socket open (i.e. every connection object created by client::connect or server::listen (via accept) requires a file descriptor. Default limits per process are typically low. Mac OS X is 256, many linuxes are 1024. Enabling higher numbers of concurrent connections requires several adjustments.

UNIX machines can use getrlimit and setrlimit to raise the per process limit. Depending on system settings this may require the process to be run as root. An example of how to do this is implemented in policy-refactor/broadcast_server. I plan to standardize this and get a windows implementation and put it in a utility method somewhere. This seems like something websocket servers will want to do.

Increasing maximums. Some operating systems have default limits on how high setrlimit can set file descriptor limits. For example Mac OS X's kernel has a default limit of 12288 file descriptors per process. You can raise this limit with a terminal command. Ex: $sudo launchctl limit maxfiles 1000000 1000000$. This will not survive a reboot without setting up additional launchctl config. (see: http://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard)

Port Limits (clients only)