Posts Tagged ‘apache’

Bandwidth limiting in Apache2

July 16th, 2009

Serving large files from a web server can be a pain, specially if you have limited bandwidth. The ultimate goal is to offer the best service to each user, that’s why it’s a good idea to sometimes limit or throttle the available bandwidth for each user.

In the Ubuntu repositories you can find the modules libapache2-mod-bw for Apache which will help you manage the the available bandwidth each user gets when downloading a file from Apache web server.

This article assumes you already have a functional Apache installation

Install mod_bw using apt-get.

sudo apt-get install libapache2-mod-bw

And enable the module using a2enmod bw.

sudo a2enmod bw

Now add the following to /etc/apache2/sites-available/default. The intention is to limit the bandwidth available to every user to 10Kb/s. Double the value in Bandwidth all if you wish to increase the rate.

ServerAdmin webmaster@localhost
 
        BandwidthModule On
        ForceBandWidthModule On
        Bandwidth all 10240
        MinBandwidth all -1

Restart Apache web server for the changes to take effect.

sudo /etc/init.d/apache restart

Apache Optimization For Low Resources

January 3rd, 2008

Running a server with low resources can be a pain but also an opportunity to learn and optimize it then you can rest assured that all possible solutions were used. From my experience web and database servers consume the most resources on a shared environment, remember that you can always increment or reduce as you see fit and the settings are similar to the ones used for a low traffic site.

The default configuration file for Apache2 can be found at.
/etc/apache2/apache2.conf

Using
IfModule mpm_prefork_module

StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 20
MaxRequestsPerChild 0

Brief description of options

StartServers
How many child server should be started by httpd (parent server).

MinSpareServers
Minimum number of server processes kept spare.

MaxSpareServers
Maximum number of server processes kept spare.

MaxClients
Maximum number of server processes allowed to start.

MaxRequestsPerChild
Maximum number of requests a process can server .

Apache tries to start and stop servers based on the current load for example if traffic decreases and too many idle server are running Apache will kill some until it reaches the number specified in “MinSpareServers”. On the other hand if a lot of request arrive in a short or close amount of time and few servers are running Apache will start more servers up to the number specified in MaxClients .

Configuration example for a low traffic site.

Using
IfModule mpm_prefork_module

StartServers 1
MinSpareServers 1
MaxSpareServers 8
MaxClients 10
MaxRequestsPerChild 400

Dont forget to restart the webserver.
sudo /etc/init.d/apache2 reload

Soon I will have a post on reducing the load MySQL places on a server.