Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 May 2004 19:57:19 -0700
From:      "David Schwartz" <davids@webmaster.com>
To:        "FreeBSD STABLE" <freebsd-stable@freebsd.org>
Subject:   RE: Which resource am I running out of here?
Message-ID:  <MDEHLPKNGKAHNMBLJOLKMENNMCAA.davids@webmaster.com>
In-Reply-To: <20040519192229.GN457@cashmere.blitzed.org>

next in thread | previous in thread | raw e-mail | index | archive | help

> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?MDEHLPKNGKAHNMBLJOLKMENNMCAA.davids>