Which resource am I running out of here?

David Schwartz davids at webmaster.com
Sat May 22 19:58:11 PDT 2004


> Another suggested I was running out of ephemeral ports:

	You almost certainly are.

> $ sysctl -a | grep portrange
> net.inet.ip.portrange.lowfirst: 1023
> net.inet.ip.portrange.lowlast: 600
> net.inet.ip.portrange.first: 1024
> net.inet.ip.portrange.last: 5000
> net.inet.ip.portrange.hifirst: 49152
> net.inet.ip.portrange.hilast: 65535
>
> If my application is using first -> last then I can this would be
> quite likely: I'm opening over 4000 TCP connections at once.  But I
> thought it used hifirst -> hilast.

	How does your application bind? Does it choose the port itself (it should!)
or just bind to port zero and *hope* the kernel does the right thing under
highly specialized conditions?

> I also increased kern.ipc.somaxconn from 128 to 1024 but this did
> not appear to help.  Are there any other resource limits which
> people think I should be changing?  The connections are very
> short-lived, perhaps no more than 30 seconds each, and hardly any
> data goes over them.

	You should not use TCP for this. You'll clutter the system with the
overhead of managing the dying connections.

> Okay, while writing this email I used lsof to see what TCP
> conections my app had.  They do all seem to have source ports within
> the first -> last range.

	Fix your application!

>  $ sudo sysctl net.inet.ip.portrange.last=20000
>  net.inet.ip.portrange.last: 5000 -> 20000
>
> seem to have removed my problem.  Thanks!

	Really, you should just fix the application. It's unreasonable to expect
the kernel to do the right thing when you have an exceptional situation.
Pick your own ports, and if they're in use, try another. If you want, you
can probe for 'hifirst' and 'hilast' and pick a port between those two.

	DS




More information about the freebsd-stable mailing list