Skip to content

borlak/bsocketserver

Repository files navigation

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:

  1. Build the project (make)
  2. 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:

  1. 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.
  2. Used epoll
  3. As far as the HTTP side goes, I read minimum headers, only looking for what I needed (like KEEPALIVE).
  4. 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!

About

A simple socket or HTTP server built for speed

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published