Writing my own webserver
I’ve been seriously considering writing my own webserver instead of running apache. Although apache is very good, yet, sometimes I feel things will be much funner if write this website even in C. My reasoning is although PHP is fast and APC provides a further boost, yet at one point I will have to cluster a set of machines and proxy the requests because of various tweeks that need to get done in every piece of software.
So, I started considering seriously how to write a webserver that is optimized for high requests and can make better use of memory, and how to resolve the biggest problem in C, which is crashes due to memory allocation and writing outside arrays without slowing down the C speed even a bit.
I ended up writing a small library does that memory stuff, and a small webserver and I’ve been playing with them for a while and without a surprise, I found that I can serve more than 1000 pages a second very easy without attempting to optimize dealing with strings and just with basic STL string, which in my opinion is very slow.
What I still need to do is to support the CGI stuff, so I can execute the current PHP code and run it beside the C and that will give me more time to port the website pages in phases without stopping the website, or delaying running this server.
Tags: c, code, cpp, emacs, gcc, write
June 6th, 2009 at 10:31 am
Yes, you are right. Apache is really good webserver. But sometimes it sucks! When u get much hits, it locks itself.
September 7th, 2010 at 8:50 pm
thats gr8 !! so did u add the CGI stuff ??
September 7th, 2010 at 10:28 pm
Actually, that was a while back. I actually wrote a whole webserver in cpp using stl. By default, it will execute cpp code to respond to page requests, and if that page is not defined in the cpp code it will attempt to execute a cgi php script to obtain the response. On average, it is around 100 times faster than php….. you can think about this in reverse: given an optimal cluster of 100 machines running a website using php code, you can replace that by 1 machine running cpp.