Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why bother using Apache or Nginx, etc?

Tags:

c++

c

webserver

I've been assigned a project which requires me to add some HTML page serving. This embedded system (running Linux CentOS 6.3) has some extra juice available, but also already has numerous responsibilities.

I considered Apache but tossed it due to bloat, I looked into Nginx but am now shying from that too. It just seems that I'm getting way more 'functionality' and as a result, more CPU usage than I need.

Can someone enlighten me as to why I wouldn't just implement the HTTP protocol myself using async sockets?

My specific needs are:

  1. Receive and decode GETs and POSTs.

  2. Send CSS, JS and JPG files as requested.

  3. Output header, cookie, head and body data based upon the decode of the GETs/POSTs.

Given that I don't need the myriad things these webservers offer, am I being naive in assuming this course of doing it myself? What would you suggest or warn against?

like image 967
Gary Avatar asked Dec 29 '12 15:12

Gary


2 Answers

Basically, you use a web server because then you get the functionality you want in a form that's already been tested, is more reliable than your first code is likely to be, and is supported by a large community of others. If Apache and nginx are too heavyweight for you (although nginx is pretty much characterized by how lightweight it is for heavy loads) and especially if the load you expect is very light, then look around for other options.

Wiki has a whole page of comparisons of lightweight web servers.

like image 184
Charlie Martin Avatar answered Sep 19 '22 02:09

Charlie Martin


An easy trap to fall into: thinking "I don't need all the functionality in Product X, I'll just write my own with just the functionality that I need" only to end up reimplementing Product X entirely, one newly-discovered requirement at a time.

I sort of doubt that an embedded system that can run CentOS okay is so resource-starved that it can't run Nginx comfortably (or even Apache, which people run on the Raspberry Pi just fine with appropriate configuration tweaks), given reasonable assumptions about how many pages you are actually serving. I ran it on a Pentium 266 with something like 256MB of RAM serving a few simple PHP apps that served roughly a page every two seconds, with no issues. As I recall, it's fairly modular, so you can just choose not to load the functionality you don't think you need. And, later, when your requirements change and you find out you do need it, you can just plug it back in :)

If you are really and truly concerned about resource consumption, look into web servers designed for embedded applications. I hear Cherokee is quite nice. Mongoose looks promising as well.

like image 35
tgies Avatar answered Sep 18 '22 02:09

tgies