Highland Linux User Group

Linux Community
It is currently Mon Feb 06, 2012 8:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Apache2-mpm-worker Installation
PostPosted: Fri Feb 26, 2010 9:12 am 
Offline
Moderator
User avatar

Joined: Tue Oct 03, 2006 12:27 pm
Posts: 162
Location: Inverness UK
Install apache2 is totally easy if you are using Ubuntu, simply just apt-get install .. and the rest is just configuration.

By default Apache2 is working with "pre-fork mpm" module in most cases.

prefork module is working by single control process is responsible for launching child processes which listen for connections and serve them when they arrive. Apache always tries to maintain several spare or idle server processes, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new child processes to be forked before their requests can be served.

Quote:
The worker MPM uses multiple child processes. It's multi-threaded within each child, and each thread handles a single connection. Worker is fast and highly scalable and the memory footprint is comparatively low. It's well suited for multiple processors. On the other hand, worker is less tolerant of faulty modules, and a faulty thread can affect all the threads in a child process.

The prefork MPM uses multiple child processes, each child handles one connection at a time. Prefork is well suited for single or double CPU systems, speed is comparable to that of worker, and it's highly tolerant of faulty modules and crashing children - but the memory usage is high, and more traffic leads to greater memory usage.


So the different between these 2 are "pre-fork" module is using existing child process to save time and "worker" module is using separate child process instead of "borrowing" other child process.

My server has 2GB memory, with around 200 connections simultaneously after a couple of days i have to restart Apache since the server has to deal with so many process, it "forks" the existing child process and maintain it so that it can serve faster in MP (Multi-Processing) operation.
This built up is server memory and my server could not deal with it.

I found that "worker module" is suit for my low memory server, also processing better in a busy server.

Below is installation and configuration that i use in my server and it's working great:
Code:
apt-get install apache2-mpm-worker libapache2-mod-fcgid


Code:
apt-get install php5-cgi php5-cli php5-curl php5-gd php5-ldap php5-mysql php5-sqlite php5-xsl


now restart apache for the server to take affect:

/etc/init.d/apache2 restart

The installation will remove pre-fork module and totally harmless, if your virtual hosting is already running, i would recommend you to do the configuration below for all of the virtual host file before starting to install worker module.

below is configuration for virtual host:

Code:
<VirtualHost 1.2.3.4:80>
         DocumentRoot /home/user/website/public_html/
         ServerName yourwebsite.com
         ServerAlias www.yourwebsite.com
    <Directory /home/user/website/public_html/>
        AddHandler fcgid-script .php
        FCGIWrapper /usr/lib/cgi-bin/php5 .php
        Options ExecCGI Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>
        LogLevel warn
        ServerSignature On

</VirtualHost>


finally add this to your /etc/apache2/httpd.conf

Code:
<Directory /var/www>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options +ExecCGI
</Directory>
Alias /aptitude /usr/share/doc/aptitude/html/en
Alias /apt /usr/share/doc/apt-doc

<Directory /usr/share>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options ExecCGI FollowSymlinks Indexes
</Directory>



change the IP and website, directory to suit your need, if your virtual host is different from what i do and what you see, and you only have to add the following code to virtual host file:

Code:
        AddHandler fcgid-script .php
        FCGIWrapper /usr/lib/cgi-bin/php5 .php
        Options ExecCGI Indexes FollowSymLinks MultiViews




I would do the configuration first and run the "apt-get install" after, so that your server will stay "alive" all the time.

because if you do the "apt-get install" first you may have to take time to config.

For more info of each module visit:

http://httpd.apache.org/docs/2.1/mod/prefork.html
http://httpd.apache.org/docs/2.0/mod/worker.html

tada
----------------------------
Nguyen

_________________
Computers are like air conditioners, They stop working properly when you open Windows!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 26, 2010 9:44 am 
Offline
Moderator
User avatar

Joined: Tue Oct 03, 2006 12:27 pm
Posts: 162
Location: Inverness UK
To change value of "worker" module you can edit the file

Code:
/etc/apache2/apache2.conf


Code:
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>


Change values in the module to suit your server.

_________________
Computers are like air conditioners, They stop working properly when you open Windows!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2010 6:20 pm 
Offline
Administrator
User avatar

Joined: Tue Oct 03, 2006 11:42 am
Posts: 14
Location: Internet
The "worker" module definitely the best, my server is always busy and i don't have to restart apache for a while now,

The only thing i changed after installed "worker" module was "KeepAliveTimeout" to 5 seconds instead of 25 or 35 seconds
in

/etc/apache2/apache2.conf


Code:
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


by doing it the server will stop "serving" after 5 seconds if the client can't make the connection, this would help reduce the waiting time for the next clients, and reduce memory usage also.

_________________
I have nothing to do with Windows, I refuse to talk to Billgates.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2010 Highlands Linux Users Group