본문으로 건너뛰기

apache MPM prefork 방식과 worker 방식의 차이점은 무엇인가요?

💡 요약 정리

  • apache MPM은 요청을 자식 프로세스로 분배하는 모듈입니다.
  • prefork 방식은 프로세스를 복제하여 처리하며 메모리 사용량이 큽니다.
  • worker 방식은 쓰레드 기반으로 메모리 효율이 높고, 고트래픽 서버에 유리합니다.
  • 설치 시 prefork는 기본 옵션이며, worker는 --with-mpm=worker 옵션이 필요합니다.
  • 설치 후 MPM 방식을 httpd -l 명령어로 확인할 수 있습니다.

1. MPM이란?

  • MPM(Multi-Processing Module)은 Apache가 수신한 요청을 자식 프로세스에게 분배하여 처리하는 방식입니다.

2. MPM 모듈 종류

2.1 Prefork

  • 실행 중인 프로세스를 복제하여 실행하며, 메모리 영역까지 함께 복제합니다.
  • 이로 인해 프로세스가 소비하는 메모리가 많습니다.

2.2 Worker

  • Apache 프로세스가 thread를 생성하여 요청을 thread 단위로 처리합니다.
  • 최대 64개의 thread 처리가 가능합니다.

3. prefork 방식과 worker 방식의 차이점

  • Worker는 Prefork에 비해 적은 메모리를 사용합니다.
  • Worker 방식은 통신량이 많은 서버에 적절한 형태입니다.
  • Prefork 방식은 안전하지 않은 제3자가 만든 모듈을 사용할 수 있습니다.
  • Prefork 방식은 디버깅이 빈약한 플랫폼에서 디버깅이 더 쉽습니다.

4. Prefork 방식 설치 방법

4.1 설치

  • 소스 컴파일 시 --with-mpm=prefork 옵션을 추가합니다.
  • 기본적으로는 별도 옵션 없이도 prefork 방식으로 설치됩니다.
[root@localhost ~]# cd /usr/local/src/httpd-2.2.14
[root@localhost httpd-2.2.14]# ./configure --prefix=/svc/test/web/apache --with-mpm=prefork --enable-so --enable-ssl
[root@localhost httpd-2.2.14]# make
[root@localhost httpd-2.2.14]# make install

4.2 Max Client 수정

  • source 디렉터리 내 server/mpm/prefork 디렉터리에서 prefork.c 파일을 수정 후, 다시 컴파일합니다.
[root@localhost ~]# cd /usr/local/src/httpd-2.2.17/server/mpm/prefork
[root@localhost prefork]# cat prefork.c | grep DEFAULT_SERVER_LIMIT
#ifndef DEFAULT_SERVER_LIMIT
#define DEFAULT_SERVER_LIMIT 2048
static int server_limit = DEFAULT_SERVER_LIMIT;
[root@localhost prefork]#

4.3 설치 방식 확인

  • Apache 설치 완료 후 데몬 실행한 뒤 다음 명령어로 확인할 수 있습니다.
[root@localhost httpd-2.2.14]# /svc/test/web/apache/bin/httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  ~
  mod_ssl.c
  prefork.c
  http_core.c
  mod_mime.c
  ~
  mod_so.c
[root@localhost httpd-2.2.14]#

5. Worker 방식 설치 방법

5.1 설치

  • 소스 컴파일 시 --with-mpm=worker 옵션을 추가합니다.
[root@localhost ~]# cd /usr/local/src/httpd-2.2.14
[root@localhost httpd-2.2.14]# ./configure --prefix=/svc/test/web/apache --with-mpm=worker --enable-so --enable-ssl
[root@localhost httpd-2.2.14]# make
[root@localhost httpd-2.2.14]# make install

5.2 Max Client 수정

  • source 디렉터리 내 server/mpm/worker 디렉터리에서 worker.c 파일을 수정 후, 다시 컴파일합니다.
  • worker 방식은 하나의 프로세스가 여러 thread를 생성해 처리하므로, DEFAULT_SERVER_LIMITDEFAULT_THREAD_LIMIT 값도 같이 조정해야 합니다.
[root@localhost ~]# cd /usr/local/src/httpd-2.2.17/server/mpm/worker/
[root@localhost worker]# cat worker.c | grep DEFAULT_SERVER_LIMIT
#ifndef DEFAULT_SERVER_LIMIT
#define DEFAULT_SERVER_LIMIT 256
static int server_limit = DEFAULT_SERVER_LIMIT;

[root@localhost worker]# cat worker.c | grep DEFAULT_THREAD_LIMIT
#ifndef DEFAULT_THREAD_LIMIT
#define DEFAULT_THREAD_LIMIT 64
static int thread_limit = DEFAULT_THREAD_LIMIT;
[root@localhost worker]#

5.3 설치 방식 확인

  • Apache 설치 완료 후 데몬 실행한 뒤 다음 명령어로 확인할 수 있습니다.
[root@localhost httpd-2.2.14]# /svc/test/web/apache/bin/httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  ~
  mod_ssl.c
  worker.c
  http_core.c
  mod_mime.c
  ~
  mod_so.c
[root@localhost httpd-2.2.14]#