동시접속자 수(MaxRequestWorkers) 기준으로 mpm값 튜닝
Apache 2.4 버전부터는 event 모드가 기본값으로 해당 모드를 기준으로 하였음
참고
https://httpd.apache.org/docs/2.4/mod/mpm_common.html#startservers
mpm_common - Apache HTTP Server Version 2.4
This controls the directory to which Apache httpd attempts to switch before dumping core. If your operating system is configured to create core files in the working directory of the crashing process, CoreDumpDirectory is necessary to change working directo
httpd.apache.org
https://httpd.apache.org/docs/2.4/en/mod/event.html
event - Apache HTTP Server Version 2.4
Apache MPM event Summary The event Multi-Processing Module (MPM) is designed to allow more requests to be served simultaneously by passing off some processing work to the listeners threads, freeing up the worker threads to serve new requests. To use the ev
httpd.apache.org
https://funfunit.tistory.com/154
[Apache | 튜닝] httpd_mpm 설정
1. mpm 종류 prefork, worker, event Apache 2.4 이후로는 event가 Default가 되었으며, prefork 또는 worker로 하기 위해서는 apache 컴파일 시 -with-mpm=prefork 또는 -with-mpm=worker 옵션을 추가하면 됨 2. 장단점 (1)prefork -
funfunit.tistory.com
2.4 버전 기준 각 모드 기본값)
prefork)
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of connections a server process serves
# before terminating
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>
worker)
# worker MPM
# StartServers: initial number of server processes to start
# 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
# MaxRequestWorkers: maximum number of worker threads
# MaxConnectionsPerChild: maximum number of connections a server process serves
# before terminating
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
event)
# event MPM
# StartServers: initial number of server processes to start
# 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
# MaxRequestWorkers: maximum number of worker threads
# MaxConnectionsPerChild: maximum number of connections a server process serves
# before terminating
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
mpm 설정 지시자)
※ 각 기본값은 worker, event를 기준으로 작성하였음
지시자 | 기본값 | 설명 |
StartServers | prefork 5 worker 3 event 3 |
서버 기동 시 생성되는 자식 프로세스 수 자식 프로세스 수는 서버 부하에 따라 동적으로 늘어나고 줄어듦 |
ServerLimit | 16 | 구성 가능한 프로세스 수의 상한 필요한 값 이상으로 설정하면 불필요한 메모리 낭비 가능성이 있음 ThreadLimit 지시자와 함께 사용 MaxRequestWorkers, ThreadsPerChild 값 수정시 함께 수정 |
MinSpareThreads | 75 | 유휴 스레드 최솟값 |
MaxSpareThreads | 250 | 유휴 스레드 최댓값 |
ThreadsPerChild | 25 | 자식 프로세스당 생성되는 스레드 수 서버 기동시 생성하고 더 이상 생성하지 않음 ThreadLimit 값을 초과할 수 없음 |
MaxRequestWorkers MaxClients(2.2) |
400 | 동시에 처리될 최대 연결 수(동시 접속자 수) 클라이언트에 제공할 스레드 수 제한 이 값을 16 이상으로 증가시키려면 ServerLimit 값도 증가시켜야 함 ThreadPerChild(25) * ServerLimit(16) |
ThreadLimit | 64 | 자식 프로세스당 생성되는 스레드 수 상한 필요한 값 이상으로 설정하면 불필요한 메모리 낭비 가능성이 있음 |
MaxConnectionsPerChild MaxRequestsPerChild(2.2) |
0(무제한) | 자식 프로세스가 살아있는 동안 처리할 연결 수 제한 0이 아닌 값으로 설정할 경우 메모리 누수로 인해 소비할 수 있는 메모리양이 제한될 수 있음 |
AsyncRequestWorkerFactor | 2 | 프로세스당 동시 연결 제한 하나의 프로세스는 현재 connection 수가 "ThreadsPerChild + (AsyncRequestWorkerFactor * number of idle workers)" 보다 작을 때만 새로운 connection을 맺음 |
mpm 값 설정시 계산식)
4의 배수로 세팅하는 것이 좋음
MaxRequestWorkers = ServerLimit * ThreadsPerChild
아래 두 가지는 공식적인 내용은 아니고 경험적인 내용임
MinSpareThreads = StartServers * ThreadsPerChild
MaxSpareThreads = (StartServers ~ ServerLimit 사이의 값) * ThreadsPerChild
[설정 예시]
MaxRequestWorkers = ServerLimit * ThreadsPerChild
MaxRequestWorkers 수를 기준으로 ServerLimit * ThreadsPerChild 계산식을 맞춰주면 되고, 나머지 요소는 서버 리소스에 따라 설정할 것
동시접속자 수 1024 세팅)
StartServers 4
MinSpareThreads 512
MaxSpareThreads 1024
ThreadsPerChild 64
MaxRequestWorkers 1024
MaxConnectionsPerChild 0
AsyncRequestWorkerFactor 2
동시접속자 수 2048 세팅)
StartServers 16
ServerLimit 32
MinSpareThreads 512
MaxSpareThreads 1024
ThreadPerChild 64
MaxRequestWorkers 2048
MaxConnectionsPerChild 0
AsyncRequestWorkerFactor 2
동시접속자 수 4096 세팅)
StartServers 32
ServerLimit 32
MinSpareThreads 1024
MaxSpareThreads 2048
ThreadsPerChild 128
ThreadLimit 128
MaxRequestWorkers 4096
MaxConnectionsPerChild 0
AsyncRequestWorkerFactor 2
MaxRequestWorkers 적정 값 계산 방법)
(총 메모리의 80% - 아파치가 사용하고 있는 메모리 크기 - 시스템에 기본적으로 설치되어 있는 agent 프로그램이 사용하는 메모리 크기) / 아파치 프로세스 1개가 사용하고 있는 메모리
Apache 사용 메모리)
ps aux | grep httpd | awk '{print $6}' | awk '{total = total + $1} END {print total/1024}'
Apache 프로세스 개수)
ps aux | grep httpd | wc -l
아파치 프로세스 1개의 사용 메모리)
Apache 사용 메모리 / Apache 프로세스 개수
MaxRequestWorkers 계산 예제)
총 메모리 * 0.8 = 2048 * 0.8 = 1638.4
Apache 사용 메모리: 102.355
시스템 agent 사용 메모리 = 0
Apache 프로세스 1개 사용 메모리 = 102.355 / 18 = 5.68
MaxRequestWorkers = (1638.4 - 102.355 - 0) / 5.68 = 270
'WEB > APACHE' 카테고리의 다른 글
13. Apache 멀티 프로세스 (0) | 2024.05.16 |
---|---|
12.1. Apache + Weblogic 연동시 에러 (0) | 2023.06.26 |
12. Apache + Weblogic 연동 (0) | 2023.06.26 |
11. Apache + Tomcat 연동 (0) | 2023.06.26 |
10. Cache-Control (0) | 2023.06.26 |