Making Apache websites faster

Source: Internet
Author: User
Article Title: Making Apache websites faster. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

The performance improvement of Apache 2.0 is the most attractive. on Unix systems that support POSIX Threads, Apache can use different MPM to run in a mix of multi-process and multi-thread modes to enhance the scalability of some configurations. compared with Apache 1.3, version 2.0 has made a lot of Optimizations to improve processing capabilities and scalability, and most improvements will take effect by default. however, at the time of compilation and running, 2.0 also has many options that can significantly improve the performance.

MPM (Multi-Processing Modules, Multi-channel Processing module) is the core feature that affects performance in Apache2.0.

To put it bluntly, the introduction of MPM is the most important change in Apache 2.0. as you know, Apache is based on modular design, while Apache 2.0 extends the most basic functions of modular design to Web servers. the server is loaded with a multi-channel processing module, which is responsible for binding the network port of the Local Machine, accepting requests, and scheduling sub-processes to process requests. extended modular design has two important benefits:

◆ Apache supports multiple operating systems in a more concise and effective manner;

◆ Servers can be customized according to the special needs of the site.

At the user level, MPM looks very similar to other Apache modules. The main difference is that at any time, only one MPM can be loaded into the server.

The following uses Linux RedHat AS3 as a platform to demonstrate how to specify MPM in Apache 2.0.

# Wget http://archive.apache.org/dist/httpd/httpd-2.0.52.tar.bz2

# Tar jxvf httpd-2.0.52.tar.bz2

# Cd httpd-2.0.52

#./Configure -- help | grep mpm

Display: -- with-mpm = MPM Choose the process model for Apache to use. MPM = {beos | worker | prefork | mpmt_os2 | perchild | leader | threadpool}

The preceding operation is used to select the MPM module to use. beos and mpmt_os2 are the default MPM on BeOS and OS/2 respectively. perchild is designed to run different sub-processes with different user and group identities. this is especially useful when running multiple virtual hosts that require CGI, and it is better than the SuExec mechanism in version 1.3. the leader and threadpool are both worker-based variants and are still in the experimental stage. In some cases, they will not work as expected. Therefore, Apache is not officially recommended. therefore, we mainly describe the product-level MPM with the highest performance relationship between prefork and worker.

  How prefork works

If "-- with-mpm" is not used to explicitly specify an MPM, prefork is the default MPM on Unix platforms. the pre-Dispatch process method adopted by Apache 1.3 is also used. prefork itself does not use threads. Version 2.0 uses it to maintain compatibility with version 1.3. On the other hand, prefork uses a separate sub-process to process different requests, processes are independent of each other, which makes them one of the most stable MPM.

The working principle of prefork is that after the control process initially creates a "StartServers" sub-process, it creates a process to meet the needs of the MinSpareServers settings, waits for one second, creates two more, and then waits for one second, create four more ...... In this way, the number of Created processes is increased exponentially, up to 32 processes per second until the value set by MinSpareServers is met. this is the origin of prefork. this mode eliminates the need to generate new processes when requests arrive, thus reducing system overhead and increasing performance.

  Working principle of worker

Compared with prefork, worker is a brand new MPM that supports multi-thread and multi-process hybrid models in version 2.0. because threads are used for processing, a relatively large number of requests can be processed, and the overhead of system resources is smaller than that of process-based servers. however, worker also uses multiple processes, and each process generates multiple threads to obtain the stability of the process server. this kind of MPM will be the trend of Apache 2.0.

The working principle of worker is that the main control process generates a "StartServers" subprocess. Each subprocess contains a fixed number of ThreadsPerChild threads, and each thread processes Requests independently. similarly, in order not to generate a thread when the request arrives, MinSpareThreads and MaxSpareThreads set the minimum and maximum number of Idle threads, while MaxClients sets the total number of threads in all sub-processes. if the total number of threads in the existing sub-process cannot meet the load, the control process will derive a new sub-process.

     
      
# I will compile and install it in worker mode #. /configure -- prefix =/usr/local/apache -- with-mpm = worker -- enable-so (let it support the DSO function, so that the module can be dynamically loaded later) # make install # cd/usr/local/apache/conf # vi httpd. conf
      
       
StartServers 2 MaxClients 150 ServerLimit 25 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 25 ThreadsPerChild 25 MaxRequestsPerChild 0
      
     

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.