From owner-freebsd-net@FreeBSD.ORG Mon Aug 20 16:41:50 2007 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4BFE216A419 for ; Mon, 20 Aug 2007 16:41:50 +0000 (UTC) (envelope-from tom@tomjudge.com) Received: from s200aog14.obsmtp.com (s200aog14.obsmtp.com [207.126.144.128]) by mx1.freebsd.org (Postfix) with SMTP id A647C13C428 for ; Mon, 20 Aug 2007 16:41:49 +0000 (UTC) (envelope-from tom@tomjudge.com) Received: from source ([217.206.187.80]) by eu1sys200aob014.postini.com ([207.126.147.11]) with SMTP; Mon, 20 Aug 2007 16:41:44 UTC Received: from [10.0.0.89] (bill.mintel.co.uk [10.0.0.89]) by rodney.mintel.co.uk (Postfix) with ESMTP id C070F181506; Mon, 20 Aug 2007 17:19:14 +0100 (BST) Message-ID: <46C9BF02.5050007@tomjudge.com> Date: Mon, 20 Aug 2007 17:19:14 +0100 From: Tom Judge User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Igor Sysoev References: <20070820151142.GA20183@rambler-co.ru> In-Reply-To: <20070820151142.GA20183@rambler-co.ru> Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: maximum number of outgoing connections X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Aug 2007 16:41:50 -0000 Igor Sysoev wrote: > It seems that FreeBSD can not make more than > > net.inet.ip.portrange.last - net.inet.ip.portrange.first > > simultaneous outgoing connections, i.e., no more than about 64k. > > If I made ~64000 connections 127.0.0.1:XXXX > 127.0.0.1:80, then > connect() to an external address returns EADDRNOTAVAIL. > > net.inet.ip.portrange.randomized is 0. > > sockets, etc. are enough: > > ITEM SIZE LIMIT USED FREE REQUESTS FAILURES > socket: 356, 204809, 13915, 146443, 148189452, 0 > inpcb: 180, 204820, 20375, 137277, 147631805, 0 > tcpcb: 464, 204800, 13882, 142102, 147631805, 0 > tcptw: 48, 41028, 6493, 11213, 29804665, 0 > > I saw it on 6.2-STABLE. > > In an ideal world (Not sure if this is quite correct for FreeBSD) TCP connections are tracked with a pair of tupels source-addr:src-port -> dst-addr:dst-port As your always connecting to the same destination service 127.0.0.1:80 and always from the same source IP 127.0.0.1 then you only have one variable left to change, the source port. If you where to use the hole of the whole of the port range minus the reserved ports you would only ever be able to make 64512 simultaneous connections. In order to make more connections the first thing that you may want to start changing is the source IP. If you added a second IP to you lo0 interface (say 127.0.0.2) and used a round robin approach to making your out bound connections then you could make around 129k outbound connections. I am not sure if there are any other constraints that need to be taken into account such as the maximum number of sockets, RAM etc.... Tom