Date: Tue, 13 Nov 2012 08:23:38 -0200 From: Friedrich Locke <friedrich.locke@gmail.com> To: freebsd-questions@freebsd.org Subject: high performance server design approach Message-ID: <CANMDHqfuEYw=hDRN2MUPao50cS9UkhzOsqeVnhSNzp8g9RUd4A@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANMDHqfuEYw=hDRN2MUPao50cS9UkhzOsqeVnhSNzp8g9RUd4A>