Linux – More than 65536 TCP connections on Linux

linuxtcp

I'm stuck trying to setup more than 65536 outgoing TCP connections from a Linux (RedHat5) box.

I have already configured both outgoing and accepting boxes to allow enough file descriptors.

I don't believe there is a problem on the accepting side – I have multiple target boxes, each with multiple IP addresses and I'm using multiple ports.

On the outgoing side I don't believe I'm hitting a limit per IP address – I'm using multiple IP addresses and ports (I'm opening connections from ports 30,000 – 60,000 for each of several IP addresses).

Is there some Linux kernel tunable parameter I'm missing? Or some fundamental limit in TCP?

The failure is that my app for opening the connections is hanging in the connect() call.

Thanks for any help
NickB

Best Answer

Here is a blog where somebody got > 1,000,000 outbounds from a box.

  • Richard Jones, MetaBrew.com, 2008-11-04, A Million-user Comet Application with Mochiweb, Part 3, section Turning it up to 1 Million (Archived here.)

In Part 1, we set the range to "1024 65535" - meaning there are 65535-1024 = 64511 unprivileged ports available. Some of them will be used by other processes, but we'll never get over 64511 client connections, because we'll run out of ports.

...

So let's bring up 17 new IP addresses, with the intention of making 62,000 connections from each - giving us a total of 1,054,000 connections