From owner-freebsd-hackers Thu Nov 16 15:55: 5 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from repulse.cnchost.com (repulse.concentric.net [207.155.248.4]) by hub.freebsd.org (Postfix) with ESMTP id B067437B4CF for ; Thu, 16 Nov 2000 15:55:03 -0800 (PST) Received: from bitblocks.com (ts002d47.oak-ca.concentric.net [206.173.201.107]) by repulse.cnchost.com id SAA07155; Thu, 16 Nov 2000 18:54:53 -0500 (EST) [ConcentricHost SMTP Relay 1.10] Message-ID: <200011162354.SAA07155@repulse.cnchost.com> To: FengYue Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Multithreaded tcp-server or non-blocking ? In-Reply-To: Your message of "Thu, 16 Nov 2000 15:20:29 PST." Date: Thu, 16 Nov 2000 15:54:47 -0800 From: Bakul Shah Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > why not just bind to the port and then spawn off some processes (like 20 > in his case) to do the accept(), once the accept() returns successfully just > take care of the request, close the connection and then goes back > to accept(). Simple, easy, and even scales pretty well. Since > it's freebsd, you even don't need to worry about putting a lock > around the accept() call. Yes, this is definitely simpler and preferable when servicing a small number of concurrent requests. But you have to spawn off as many processes as the worst case number of concurrent requests you want to service since while all the processes are busy servicing, additional connections are not being accepted (after the listen backlog is exhausted). By using one process to accept connections, hand out requests and create processes as needed and by allowing idle processes to exit, you can dynamically adjust the number of server processes (e.g. depending on some user input or system load or resource use or day of time or whatever). You can also reject additional requests more intelligently (or redirecting them elsewhere) as opposed to not just accepting new connections. So this is more flexible at a small increase in complexity. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message