From owner-freebsd-questions@FreeBSD.ORG Fri Oct 20 08:05:35 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 43BE916A412 for ; Fri, 20 Oct 2006 08:05:35 +0000 (UTC) (envelope-from girishvenkatachalam@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.234]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB87143D53 for ; Fri, 20 Oct 2006 08:05:34 +0000 (GMT) (envelope-from girishvenkatachalam@gmail.com) Received: by wx-out-0506.google.com with SMTP id t4so881467wxc for ; Fri, 20 Oct 2006 01:05:34 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:date:from:to:subject:message-id:reply-to:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent; b=dr326S9PqHNw8pF7P9gV/89J9z91qCFuc9tyJzCm4eVCKg6UIfegEoor9/B3BeED2pZpIOveAmpYiPOBhKGanHjki3UyHZTelwehIw/zjzZ/OMac/WqW9pPSmgTr6rxtp742ecc+Ww+8IsqRyGDP+PIC/kvEpNsS/U2Yi/SJZtw= Received: by 10.70.29.7 with SMTP id c7mr272205wxc; Fri, 20 Oct 2006 01:05:33 -0700 (PDT) Received: from lakshmi.susmita.org ( [59.92.61.145]) by mx.google.com with ESMTP id i34sm1824286wxd.2006.10.20.01.05.31; Fri, 20 Oct 2006 01:05:33 -0700 (PDT) Received: by lakshmi.susmita.org (Postfix, from userid 1000) id A602323A9E5; Fri, 20 Oct 2006 13:35:26 +0530 (IST) Date: Fri, 20 Oct 2006 13:35:26 +0530 From: Girish Venkatachalam To: freebsd-questions Questions list Message-ID: <20061020080526.GA23594@lakshmi.susmita.org> Mail-Followup-To: freebsd-questions Questions list References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2i Subject: Re: FreeBSD 6.1 max sockets X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: girishvenkatachalam@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Oct 2006 08:05:35 -0000 On Thu, Oct 19, 2006 at 11:24:30PM +0800, ke han wrote: > I am writing a socket server deamon in C++ on FreeBSD 6.1 (or 6.2 if > this matters to your answer). What this does is accept many sockets > and does a little work with each. Each socket has low traffic but > stay connected for long periods. All these sockets get accepted > through one public ip:port (if this matters). > So my desire is two things: > 1 - good event handling for knowing which sockets have new data. I > assume kqueue is the way to go here? > 2 - I need to know what my limits are on max number of sockets. If > my system is a 64-bit install on a server with 8GB RAM, I need to > know how many sockets I can handle. Also, what options do I have to > tune this? socket buffer size? Any kernel parameters needed to tune? > As Chuck said select(2) is a good choice. That is what I used. kqueue() is more powerful and certainly much better when it comes to handling large number of sockets since kqueue(2) is very efficient when it comes to polling sockets for events. If you use select, the problem is that if you have say 2000 sockets and only one socket is available for read/write, then select has a stupid algo to figure out. Doesn't scale well. But kqueue(2) is very good at that sort of thing. Also kqueue() has a built in event mechanism that can be extended for signals and files also. If the sockets stay connected for long periods you may also want to enable TCP KEEPALIVE flag on the sockets. I don't think RAM and processor will be the bottleneck for you. Since in typical scenarios number of concurrent connected sockets don't usually hit such high limits. They come and go... HTH. Best of luck! regards, Girish