Built this initially as a "socket server", but turned into more of an HTTP server as I needed it for another project that was handling thousands of requests/second.
After reading about the C10K problem I went with epoll for this project. I had used select() in a number of other socket related projects (see my MUD repositories).
Usage as far as I remember:
- Build the project (make)
- Run bserverd.php
There are a number of configuration flags which you can see with: ./bserver -h
There is also connection profiling, which will tell you how long each part of a request is taking, from creating the connection, to receiving or sending data, etc. This is a flag you enable at process startup.
Things I did in consideration of speed:
- I built a "smart buffer" object, that keeps buffers in memory and re-uses them. It creates buffers of varying sizes and if a connection sends more data than their current buffer needs, it will be given a bigger buffer. Once the connection closes, the buffer is kept in memory, cleared, ready to be re-used.
- Used epoll
- As far as the HTTP side goes, I read minimum headers, only looking for what I needed (like KEEPALIVE).
- The profiling I mentioned above, to troubleshoot what was causing any slowness
My next phase for speed was to introduce threads and buffer lists -- see buffer_list.c and ideas.txt. But I never finished this step.
Have fun!