Serving Javascript and Images — Fast

Recently, I posted an article mainly about optimizing apache for low memory usage.  There, I noted that webservers like thttpd and lighttpd are really good at serving things fast.  I’ve been trying to optimize a site I’m playing with, and I’ve done a bit of analysis / work on using an alternative webserver.

Lighttpd wasn’t immediately in my debian apt-get list, so I went with thttpd.

The site I’m playing with has lots of images, so I took my own advice and deployed thttpd to serve up the images, and while I was at it, I moved all css and javascript over, too.  I’m using Scriptaculous, which requires the download of a large amount of javascript.

My thoughts on implementing this are first: thttpd serves up the images a LOT faster, using almost no ram.  Top doesn’t even notice that it’s running.
Second, not clogging the apache processes with images frees more apache processes for serving users.

Third, thttpd doesn’t support output compression, so I moved the javascript files back to apache, where they can be compressed with mod_deflate.  Lighttpd *does* support output compression, php, url rewriting, virtual hosts, and pretty much everything else i’d want to have.  It really looks like an amazing product, and I’m going to have to give it a try to see if lives up to the hype i’m giving it.

Oh, and in the end, I got initial page load (across the internet, cache cleared) from just over 8 seconds to 3 seconds using mod_deflate for the javascript and thttpd for the images.  Successive page loads are about 1-2 seconds.

Published by

matt

I'm a software engineer in New Orleans interested in making things, growing things, big fast computers, media convergence, and pugs.

-15 thoughts on “Serving Javascript and Images — Fast”

  1. How are you getting the different servers to handle page requests? Is it just a simple matter of running them on different ports, or are you using something that lets you pass requests from one to the other?

    It would be pretty awesome to have thttpd/lighttpd as the primary server, and have it pass off requests to Apache for URLs that match certain patterns. Or maybe even to pass all requests to Apache *except* for those which match certain patterns, depending on what you want to do.

    I wonder if that’s possible. Hmm.

  2. Yeah, i just run thttpd on port 81. People I know who run bigger sites run apache over multiple servers with thttpd on a single server to handle all image and css requests.

    I’m thinking I need to test out running lighttpd *only* because it does everything i want — compression, virtual hosts, php, low memory, etc. I’m just curious how low its memory usage *actually* is.

  3. hey very nice i found this very useful. i’m ona 128MB vps cheap hosting plan and i’m always getting above 128, so i’ll try this stuff!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>