Go Back   Technology Forums > Computer Forums > Linux Forum

Forums discussing various aspects of running a LAMP based platform.


Lighttpd + Apache 2.2 mod_proxy Setup


Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 09-27-2007, 09:24 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default Lighttpd + Apache 2.2 mod_proxy Setup

Here's how we lighten the load on some of our apache servers.

1) Setup Apache 2.2 with the various mod_proxy modules enabled. The ones that are important to us are

mod_proxy.c
mod_proxy_connect.c
mod_proxy_http.c
mod_headers.c

These are usually compiled in statically using the following directives in the ./configure script.

Code:
 --enable-proxy --enable-proxy-httpd --enable-proxy-balancer --enable-headers
2) Grab the latest version of Lighttpd 1.5 (recommended over 1.4x) from www.lighttpd.net. The latest releases are usually announced here ( http://blog.lighttpd.net/ ) and are generally of very high quality and suitable for "bleeding edge production servers".

The lighttpd setup is fairly simple ..

Code:
./configure --prefix=/usr/local/light

make

make install
Reply With Quote
  #2 (permalink)  
Old 09-27-2007, 09:42 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

To install the servers, in most situations, a make install should copy the files over to the appropriate directories.

Make sure that Apache works ok. Since we configure the proxy modules statically, we don't need additional lines in there to load the proxy modules. In your case, you might need them.

We use named virtual hosts. So our setup for any given website looks like this.

Code:
<VirtualHost XX.XX.XX.XX:80>
    ServerAlias www.domain.com
    ServerAdmin webmaster@domain.com
    DocumentRoot /home/domain/public_html
    ServerName domain.com
    CustomLog /usr/local/apache/domlogs/domain.com combined
</VirtualHost>
Create two directories under /home/domain/public_html for testing purposes .. we'll call them apps and static.

The static directory is where all the static files should be present (gif, css, js etc etc). These are essentially files that will be transported to the client's web browser without any alteration on the server.

For sake of experiment, create a file called logo.png in the static directory.

From the linux console or a web browser on your client computer, try and access this file.

Console:
Code:
wget http://www.domain.com/static/logo.png 
or
ab http://www.domain.com/static/logo.png
If you an access the file, apache is working ok.

Now install lighttpd... with a few changes to its default configuration.

1) Modules loaded
Code:
server.modules              = (
                                "mod_access",
                               "mod_simple_vhost",
                                "mod_deflate",
                                "mod_accesslog" )
We use
1) mod_simple_vhost so that lighttpd can understand handle multiple hosts.
2) mod_deflate so that we can compress some of the css and js files (as appropriate)
3) mod_accesslog to debug and test.

Port to bind on
Code:
## bind to port (default: 80)
server.port                = 81

Tell ligttpd where your domain's web accessible files are.

Code:
$HTTP["host"] == "www.domain.com" { server.document-root = "/home/domain/public_html" }

Once you start lighttpd, you can test it again, using the same tools as before.

Code:
wget http://www.domain.com:81/static/logo.png 
or
ab http://www.domain.com:81/static/logo.png
The difference being, you are testing the webserver on port 81.

Once the requests are successful (and check your logs to make sure there are no errors..) you now need to turn mod_proxy, in apache to redirect requests to lighttpd.
Reply With Quote
  #3 (permalink)  
Old 09-27-2007, 09:43 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

All you need now, are three simple statements to begin the proxying from Apache.

Code:
ProxyRequests Off
ProxyPreserveHost On

ProxyPass /static/ http://127.0.0.1:81/static/
ProxyPassReverse /static/ http://127.0.0.1:81/static/
ProxyRequests Off prevents your apache setup from being used as an open proxy (VERY DANGEROUS).

ProxyPreserveHost On ensures that the host name is sent to the target server (lighttpd in this case on port 81) intact.

ProxyPass and ProxyPassReverse redirect the requests made to those directories to the lighttpd server running on port 81.

Additional directories can be added as required.
Code:
ProxyPass /images/ http://127.0.0.1:81/images/
ProxyPassReverse /images/ http://127.0.0.1:81/images/
Restart Apache.

Now, do a quick test.

You should see the logo.png request being logged in the lighttpd access log and the report from "ab" should show something like this.

Quote:
Server Software: lighttpd/1.5.0
Server Hostname: www.domain.com
Server Port: 80
Note how the server software is now Lighttpd even though Apache is running on port 80.

Now for some simple benchmarks.
Reply With Quote
  #4 (permalink)  
Old 09-27-2007, 09:43 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

Our benchmarks show:

ab -n 5000 http://www.domain.com/static/logo.png

Code:
Server Software:        lighttpd/1.5.0
Server Hostname:        www.domain.com
Server Port:            80

Document Path:          /static/logo.png
Document Length:        4692 bytes

Concurrency Level:      1
Time taken for tests:   5.40997 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      24630000 bytes
HTML transferred:       23460000 bytes
Requests per second:    991.87 [#/sec] (mean)
Time per request:       1.008 [ms] (mean)
Time per request:       1.008 [ms] (mean, across all concurrent requests)
Transfer rate:          4771.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0      19
Processing:     0    0   0.6      0      12
Waiting:        0    0   0.3      0       6
Total:          0    0   0.6      0      20

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      1
  95%      1
  98%      1
  99%      2
 100%     20 (longest request)
With a concurrency level of 100 requests
ab -n 5000 -c 100 http://www.domain.com/static/logo.png

Code:
Server Software:        lighttpd/1.5.0
Server Hostname:        www.domain.com
Server Port:            80

Document Path:          /static/logo.png
Document Length:        4692 bytes

Concurrency Level:      100
Time taken for tests:   1.401939 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      24658286 bytes
HTML transferred:       23486180 bytes
Requests per second:    3566.49 [#/sec] (mean)
Time per request:       28.039 [ms] (mean)
Time per request:       0.280 [ms] (mean, across all concurrent requests)
Transfer rate:          17176.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       5
Processing:     2    5   3.2      5     148
Waiting:        0    4   2.1      4      37
Total:          2    5   3.2      5     150

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      5
  75%      6
  80%      6
  90%      7
  95%      8
  98%     10
  99%     12
 100%    150 (longest request)
Lets see how apache handles these.

Place the logo.png in a directory that is not proxied.

Code:
Server Software:        Apache/2.2.6
Server Hostname:        www.domain.com
Server Port:            80

Document Path:          /logo.png
Document Length:        4692 bytes

Concurrency Level:      1
Time taken for tests:   6.129123 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      25140000 bytes
HTML transferred:       23460000 bytes
Requests per second:    815.78 [#/sec] (mean)
Time per request:       1.226 [ms] (mean)
Time per request:       1.226 [ms] (mean, across all concurrent requests)
Transfer rate:          4005.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       4
Processing:     1    1   0.2      1       5
Waiting:        0    0   0.3      0       4
Total:          1    1   0.2      1       5

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      2
 100%      5 (longest request)
And at 100 concurrent requests.

Code:
Server Software:        Apache/2.2.6
Server Hostname:        www.domain.com
Server Port:            80

Document Path:          /logo.png
Document Length:        4692 bytes

Concurrency Level:      100
Time taken for tests:   1.757732 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      25152572 bytes
HTML transferred:       23470220 bytes
Requests per second:    2844.57 [#/sec] (mean)
Time per request:       35.155 [ms] (mean)
Time per request:       0.352 [ms] (mean, across all concurrent requests)
Transfer rate:          13974.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       2
Processing:     1   12   5.8     12      77
Waiting:        0   11   5.5     11      75
Total:          1   12   5.7     12      77

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     13
  75%     15
  80%     16
  90%     17
  95%     18
  98%     25
  99%     38
 100%     77 (longest request)
Reply With Quote
  #5 (permalink)  
Old 09-27-2007, 11:14 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

In conclusion on a simple test of one file over a server that is not busy.

5000 Requests (1 concurrency)

Lighttpd v/s Apache
Time Taken for Tests: 5.40997 seconds v/s 6.129123 seconds
Requests Per Second: 991.87 [#/sec] (mean) v/s 815.78 [#/sec] (mean)

5000 Requests (100 Concurrency)
Time Taken For Tests: 1.401939 seconds v/s 1.757732 seconds
Requests Per Second:
3566.49 [#/sec] (mean) v/s 2844.57 [#/sec] (mean)

And, this does not take into account the loading on the server that is produced by Apache (much higher when its serving up the requests).

So the clear winner is mod_proxy + lighttpd for serving up static content.
Reply With Quote
  #6 (permalink)  
Old 09-30-2007, 07:05 AM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

http://www.devlib.org/forums/apache-mod-proxy-t297.html

Apache v/s Squid for reverse proxying.
Reply With Quote
  #7 (permalink)  
Old 10-10-2007, 05:42 AM
Junior Member
 
Join Date: Oct 2007
Posts: 1
NeutralizeR is on a distinguished road
Default Great tutorial!

I just wanted to say thank you! Applied this to my servers and obviously apache response is now better.
Reply With Quote
  #8 (permalink)  
Old 10-10-2007, 02:13 PM
Administrator
 
Join Date: Dec 2006
Posts: 304
shri has disabled reputation
Default

Good to hear. Have a few other things we did with mod_cache that might be able to help on the front end.

Will post a few notes on the forum .. hopefully by this weekend.
Reply With Quote
Reply





Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache httpd mod_proxy errors ljohnson Linux Forum 2 12-10-2007 04:31 PM
Apache Mod_Proxy or Squid? DVDGuy Linux Forum 8 10-05-2007 02:32 AM



Advanced Search

All times are GMT -6. The time now is 06:16 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.