Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have read in a site that another benefit of having Lighttpd in front of Apache is lower number of child processes. Lighttpd will handle keep-alive and client requests while child processes of Apache gets to serve dynamic pages faster because of the very low latency communication between Lighttpd and Apache. I am trying to find the link but I am having a hard time.

Given that I already have a dedicated Lighttpd server for my static contents (img, vid, css, js, html, etc.) and another dedicated Apache server for my dynamic pages (php), I would like to implement this technique if it really has some performance gain.

1) Has anybody put a Lighttpd in front of Apache for the same purpose as explained above?
2) Is there really a performance gain on this? How much?
3) What about the overhead of Lighttpd handling down the request to Apache, is it really worth it?

Thanks!

share|improve this question
add comment

2 Answers

  1. We had lighty serving static content, and forwarding the dynamic requests to Apache on the same server but listening on another port
  2. the "forward to apache for dynamic" was not done for the purpose of performance, but just to have a single server from the point of the client, serving everything. However if you can avoid excess connections to Apache, it's a good side benefit. More connections = more processes = more memory (especially with mod_php). So, no numbers, sorry.
  3. the overhead seemed negligle compared to the hog that is Apache

That said, you should consider the Varnish reverse proxy instead of (or in front of) lighty as your frontend. It's very fast and efficient. Especially interesting for caching dynamic pages (or page fragments, using ESI), it helps reducing the backend load and absorbing the traffic spikes.

And possibly use nginx (with PHP-FCGI) as a backend instead of Apache (although it's a more complicated task than adding a Varnish frontend) (nginx can be used as frontend too, but isn't as good as a dedicated reverse proxy like Varnish). Disclaimer: I don't have nginx experience ;)

share|improve this answer
    
Upboat, use Varnish for this and not lighthttpd. –  troyengel Sep 6 '10 at 15:09
add comment

I have used to be in the same situation, suing lighttpd next to apache)for reducing load on apache.

It's better to serve static content with a light web server, as it requires less resources. Also have to mention, that PHP requires apache to run in pre-forked mode, which disables apache from running efficiently. You can distribute the load over to two, differently set up web servers, each handling the traffic it's best in.

Some implementation notes:

You have three options:

  1. modify your code and segment traffic on IP layer
  2. don't modify your code and segment traffic on application (http) layer
  3. get one of the web servers to pass requests coming to the other web server for actual serving

The first is quicker, the second requires less configuration, the third is like a mule.

I would not consider the third option if I were you, as it comes with a configuration nightmare, also, if you misconfigure something at the first web server, nothing will work and it's harder to spot where the problem is.

In the past, I needed to have a solution urgently, so I went with option 2, and utilized a reverse proxy called pound to segment requests upon static/dynamic content and distribute the load to the two different web servers.

Although it works, it requires actively monitoring the http content, which takes it toll on performance (an extra daemon running).

With option 2, you can get better performance with utilizing an extra IP for static content (static.domain.org) and get the clients refer to this static.domain.org for the content. It will still require a reverse proxy, but the proxy does not have to check the Host: header in any of the requests, so it will be quicker.

here is a configuration snippet of pound for your reference:

ListenHTTP 
        Address 195.175.71.17
        Port 80
        Client 30
        RewriteLocation 2

        Service
                HeadRequire "^[Hh]ost:\s*www.nasa.gov$"
                URL "^/static/content"
                BackEnd
                        Address 127.0.0.1
                        Port 81
                        TimeOut 300
                End
        End
        Service
                HeadRequire "^[Hh]ost:\s*www.nasa.gov$"
                BackEnd
                        Address 127.0.0.1
                        Port 80
                        TimeOut 300
                End
        End
ListenHTTP 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.