Multi-Processing Module (MPM) là gì?

MPM (Multi-Processing Module): là các module multi-processing quyết định cách thức Apache sẽ tiếp cận và xử lý các request từ client.
MPM là module trong Apache vì vậy mà ta có thể enable/disable trong cấu hình module của apache. Apache cũng yêu cầu và chỉ có thể sử dụng duy nhất 01 trong các module MPM cho cấu hình.
Hiện nay, Apache-2.4 hỗ trợ 03 modules multi-processing cho hệ thống Unix: worker, prefork và event

Worker MPM: Sử dụng nhiều child process với nhiều thread. Và mỗi thread sẽ xử lý một request tại một thời điểm.

Prefork MPM: Sử dụng nhiều child process với một thread. Tại một thời điểm thì mỗi process đó sẽ chỉ xử lý chỉ một request.

Event MPM: Sử dụng mô hình event-based, cho phép truy cập và xử lý các yêu cầu bất đồng bộ (asynchronous).
Event MPM dựa trên mô hình MPM worker, nên nó cũng gần giống với mpm worker.
Nó tạo ra nhiều child process, với nhiều thread. Mỗi parent process chịu trách nhiệm chạy các child process. Mỗi child process tạo ra một số lượng thread cố định (Số lượng thread được định nghĩa trong chỉ thị “ThreadsPerChild”).

Để hiển thị các child process được Apache sinh ra ta sử dụng lệnh:

ps -ef |grep httpd |grep -v grep

Chi tiết về MPM bạn có thể tham khảo tại: http://httpd.apache.org/docs/current/mpm.html

Cài đặt và cấu hình Apache sử dụng Event MPM

Để cài đặt Apache Web server, bạn có thể tham khảo bài viết: Cài đặt LAMP trên CentOS

Sau khi cài đặt xong vào Ip web server để kiểm tra.

Kiểm tra phiên bản Apache và MPM đang hoạt động

apachectl -V |grep -i 'version\|MPM'

Server version: Apache/2.4.6 (CentOS)
Server MPM: prefork

Version hiện tại là Apache/2.4.6 và mặc định sử dụng MPM prefork

Thông số cấu hình mặc định của mpm prefork:

<IfModule prefork.c>
    StartServers 5
    ServerLimit 256
    MinSpareServers 5
    MaxSpareServers 10
    MaxRequestWorkers 256
    MaxConnectionsPerChild 0
</IfModule>

 

Cấu hình Apache sử dụng mpm event

Chạy lệnh sau để disable module mod_mpm_prefork:

sed -i 's/.*mod_mpm_prefork.so/#&/' /etc/httpd/conf.modules.d/00-mpm.conf 

Chạy lênh sau để enable mod_mpm_event:

sed -i '/.*mod_mpm_event.so/s/^#//g' /etc/httpd/conf.modules.d/00-mpm.conf 

Restart Apache web server:

systemctl restart httpd

Check lại MPM module của Apache:

httpd -V | grep MPM  

Server MPM: event

Thông số cấu hình mpm event mặc định như sau:

ThreadsPerChild 25
StartServers 3
ServerLimit 16
MinSpareThreads 75
MaxSpareThreads 250
MaxRequestWorkers 400
MaxConnectionsPerChild 0

Để tùy chỉnh Event MPM thêm đoạn sau vào tệp tin cấu hình httpd (/etc/httpd/conf/httpd.conf)

<IfModule mpm_event_module>
      ServerLimit    100
      StartServers    12
      MinSpareThreads    25
      MaxSpareThreads   250
      ThreadLimit    64
      ThreadsPerChild    25
      MaxRequestWorkers    2500
      MaxConnectionsPerChild    0
      AsyncRequestWorkerFactor    4
</IfModule>

Thống số: MaxRequestWorkers = ServerLimit * ThreadsPerChild

 

Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *