Where i wrote listen i really meant accept. On Mon, Nov 12, 2012 at 9:04 PM, Friedrich Locke <friedrich.lo...@gmail.com>wrote:
> Hi folks, > > i am planning to write a simple web server. My initial ideia for this > server is that it will only serve static content. > So, i would like to have the best possible performance. > > I don't feel like going for multiple process since i would like to reduce > context switch required by multiple process send data to clients. I would > like to implement it using kqueue. On a single cpu/core machine it is > fairly simple to solve, but when in SMP/multicore machines i could take two > approaches (Suppose we have n cores in the system): > > First approach: > > A connection multiplexer process listens for incoming connections on port > tcp/80. When i new connection arrives it (the process) accepts it (the new > connection) and sends the fd from the incoming connection to one of the n > http server process instances and from that point on the http server > process handles it. > > Second approach: > > Starts a http server process. This process opens a socket for listening > incoming connection on port tcp/80. Than, this process forks n-1 processes. > These n-1 process will share the listening socket and starts listening to > this socket too. When a new connection arrives, the kernel wakes up one of > the n proccess and this one handles the incoming connection. While this > process is serving a request, we will have n-1 process listening and if a > new connection arrives the kernel wakes up one of the n-1 process and do > everything again and again .... > > I am no OpenBSD kernerl expert. I would like to hear from which of the > approaches would deliver better performance (this is critical for me). What > you have to say. > > Thanks a lot for your time and cooperation. > > Best regards, > > Fried.