Work out MaxRequestWorkers and ServerLimit for prefork, worker or event from your RAM, what MySQL, PHP-FPM and the OS need, and your measured Apache process size. Get a copy-ready config block.
Apache MaxRequestWorkers 계산기
서버 RAM, MySQL·PHP-FPM·OS 예약 메모리, 실측 Apache 프로세스 크기로 prefork·worker·event별 MaxRequestWorkers와 ServerLimit을 계산하고 설정 블록을 바로 복사하세요.
Run apachectl -V | grep MPM (or httpd -V) to see whether Apache uses prefork, worker or event. prefork is common with mod_php; event is the default on modern Debian, Ubuntu and RHEL builds with PHP-FPM.
2. Enter RAM and reservations
Put in total RAM, then what the OS, MySQL/MariaDB, PHP-FPM and anything else need. Check real usage with free -m and htop so Apache only gets the memory that is really left.
3. Measure the Apache process size
Copy the ps one-liner and run it during normal traffic. With prefork and mod_php a process is often 30–100 MB; measure yours instead of guessing, because modules and PHP code change it a lot.
4. Copy the config and watch the log
Paste the IfModule block into your MPM config, run apachectl configtest, then restart Apache. If the error log says "server reached MaxRequestWorkers", use the reverse calculator to see how much RAM a higher limit needs.
사용 방법
1. MPM 고르기
apachectl -V | grep MPM (또는 httpd -V)으로 Apache가 prefork, worker, event 중 무엇을 쓰는지 확인하세요. mod_php 환경은 보통 prefork이고, PHP-FPM을 쓰는 최신 Debian·Ubuntu·RHEL은 event가 기본입니다.
2. RAM과 예약 메모리 입력
총 RAM을 넣고 OS, MySQL/MariaDB, PHP-FPM 등 다른 서비스가 쓰는 메모리를 입력하세요. free -m, htop으로 실제 사용량을 확인하면 Apache에 정말 남는 메모리만 배정할 수 있습니다.
3. Apache 프로세스 크기 측정
ps 한 줄 명령을 복사해 평소 트래픽이 있을 때 실행하세요. prefork + mod_php 프로세스는 보통 30–100MB지만 모듈과 PHP 코드에 따라 크게 달라지므로 추측하지 말고 직접 측정하세요.
4. 설정 복사 후 로그 확인
IfModule 블록을 MPM 설정 파일에 붙여넣고 apachectl configtest로 확인한 뒤 Apache를 재시작하세요. 에러 로그에 "server reached MaxRequestWorkers"가 보이면 역계산기로 더 높은 값에 필요한 RAM을 확인하세요.
Frequently Asked Questions
Subtract what the OS, MySQL or MariaDB, PHP-FPM and other services need from total RAM, keep about 10% as headroom, then divide by the size of one Apache process and round down. Example for 4 GB with prefork, OS 512 MB, MySQL 1 GB and 40 MB processes: floor((4096 − 1536) × 0.9 ÷ 40) = 57. With worker or event, multiply the number of processes by ThreadsPerChild instead.
MaxRequestWorkers is the number of requests Apache serves at the same time. ServerLimit is the upper bound on the number of child processes. With prefork each process handles one request, so ServerLimit must be at least MaxRequestWorkers, and you must raise it to go above the default of 256. With worker or event, ServerLimit must be at least MaxRequestWorkers ÷ ThreadsPerChild, rounded up.
With the threaded worker and event MPMs, Apache starts whole child processes that each run ThreadsPerChild threads. The Apache 2.4 docs say MaxRequestWorkers should be an integer multiple of ThreadsPerChild; otherwise Apache rounds it down and logs a warning. The default is 16 processes × 25 threads = 400.
Run the ps and awk one-liner shown under the process-size field while the site has normal traffic. It averages the resident memory (RSS) of all apache2 processes. On RHEL, CentOS, AlmaLinux or Rocky Linux the process is called httpd. For a safer number, list the processes with ps -ylC apache2 --sort:rss and use the largest one.
Too high: under a traffic spike Apache starts more processes than RAM can hold, the server swaps and the Linux OOM killer may stop MySQL. Too low: the error log shows "server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting" and new connections wait in a queue, so pages load slowly. Use the calculated value as a starting point and watch memory and the error log.
자주 묻는 질문
총 RAM에서 OS, MySQL·MariaDB, PHP-FPM 등 다른 서비스가 쓰는 메모리를 빼고, 10% 정도 여유를 남긴 뒤 Apache 프로세스 1개 크기로 나누고 내림합니다. 예: 4GB, prefork, OS 512MB, MySQL 1GB, 프로세스 40MB → floor((4096 − 1536) × 0.9 ÷ 40) = 57. worker·event는 프로세스 수에 ThreadsPerChild를 곱합니다.
MaxRequestWorkers는 Apache가 동시에 처리하는 요청 수이고, ServerLimit은 자식 프로세스 수의 상한입니다. prefork는 프로세스 하나가 요청 하나를 처리하므로 ServerLimit이 MaxRequestWorkers 이상이어야 하고, 기본값 256을 넘기려면 ServerLimit도 올려야 합니다. worker·event는 ServerLimit이 MaxRequestWorkers ÷ ThreadsPerChild(올림) 이상이어야 합니다.
스레드 방식인 worker·event MPM은 ThreadsPerChild개 스레드를 가진 자식 프로세스를 통째로 띄웁니다. Apache 2.4 문서는 MaxRequestWorkers를 ThreadsPerChild의 정수배로 두라고 하며, 아니면 내림하고 경고를 남깁니다. 기본값은 프로세스 16개 × 스레드 25개 = 400입니다.
프로세스 크기 입력란 아래의 ps + awk 한 줄 명령을 평소 트래픽이 있을 때 실행하세요. 모든 apache2 프로세스의 상주 메모리(RSS) 평균을 MB로 보여줍니다. RHEL·CentOS·AlmaLinux·Rocky Linux는 프로세스 이름이 httpd입니다. 더 안전하게 잡으려면 ps -ylC apache2 --sort:rss로 목록을 보고 가장 큰 값을 쓰세요.
너무 크면: 트래픽이 몰릴 때 RAM에 다 들어가지 않을 만큼 프로세스가 늘어 스왑이 생기고, 리눅스 OOM killer가 MySQL을 종료시킬 수 있습니다. 너무 작으면: 에러 로그에 "server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting"이 찍히고 새 연결이 대기열에서 기다려 페이지가 느려집니다. 계산값을 출발점으로 삼고 메모리와 에러 로그를 보며 조정하세요.