From owner-freebsd-questions@FreeBSD.ORG Tue Nov 13 10:23:39 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0CF3EC64 for ; Tue, 13 Nov 2012 10:23:39 +0000 (UTC) (envelope-from friedrich.locke@gmail.com) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id D2D198FC14 for ; Tue, 13 Nov 2012 10:23:38 +0000 (UTC) Received: by mail-pb0-f54.google.com with SMTP id wz12so268761pbc.13 for ; Tue, 13 Nov 2012 02:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=vqRPvWA95Z7KMaSm4wRS0u5bvx54KwOzULMHCzV56V8=; b=iGzyJq/z+OvCy+yicc95tmt5c648rKemobfUxrGtLA7KPLDicmY1O+/Oy3MR6ytpVi rVwz3p/wl4FQoGF+IUUC2245p2wncDRTwhpprvz8ROBXzPkN4WoNJnxhpwJ2rIpVvTCF hEjeKfZMw4Jw+J9+iZ7pTmKHC1foBsv+S97SGoMKTz2AP+HpbYG461uE/W82p0mN7BkP ANKBtE1L2/v+GfntEDxBy2kISrf1gF0I19kpOvrVOdHW9E0b/yr1/PMpzQLpFtUvLLkU ObbXIAwvwDo41IyEN7/KbcFdEI1pMuuZ1vn/1cq8gEKBaHTIendfXadtJMGMG8DzheVl v/Eg== MIME-Version: 1.0 Received: by 10.68.192.66 with SMTP id he2mr65762106pbc.112.1352802218459; Tue, 13 Nov 2012 02:23:38 -0800 (PST) Received: by 10.68.238.103 with HTTP; Tue, 13 Nov 2012 02:23:38 -0800 (PST) Date: Tue, 13 Nov 2012 08:23:38 -0200 Message-ID: Subject: high performance server design approach From: Friedrich Locke To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Nov 2012 10:23:39 -0000 Hi list members, i would like to be an http server for static content only. Due to this requirement, the server should be really simple to code. But another requirement is that i would like to best possible performance. I would like to have minimal context switches and have a single process serving as many connections as possible, i feel like going for kqueue. On a single processor system, no secret. But on a SMP system the history is different. I would like to have a http process per core. The question is which decision to make: 0) To have a single process "accepting" incoming connection on port 80 and send the new socket fd to one of the http server in a round-roubin manner, or 1) Have a httpd server started. Have it performed socket, bind, listen. Then it forks n-1 childs and after forking the child, everyprocess (parent and childs) do "accept" on the socket fd listening for incoming connections. The concern here is about the kernel awaking up policy in terms of performance, i.e., awaking up more than one process when a new connection is ready to be accept (only one process will have it and the other will be put to sleep again). The first approach leads to n+1 process. The second to exactly n process. The code (only relevant part) for the second approach would be something like: sd = socket; bind(sd ...); listen; while (n) { p = fork(); if (!p) break; /* we are a child */ if (p == -1) break; /* we are the parent, error */ } nc = accept(sd ...); What you have to say ? Thanks a lot for your time and cooperation.