웹서버가 느려져서 확인했더니 장애가 발생하면서 많은 자원을 소모하고 있었다.
mysql에서도 너무 많은 접속이 있다는 에러가 있었다. 우선은 웹서버를 내렸다고 올린 다음에 웹서버 로그를 확인해 보니 아래 메세지가 뜬 이후로 계속 child process가 존재하지 않는다는 메세지기 반복해서 기록되어 있다.
[Sun Apr 02 14:26:55.682281 2023] [mpm_prefork:error] [pid 886] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Sun Apr 02 14:33:43.087232 2023] [core:warn] [pid 886] AH00045: child process 20531 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.430138 2023] [core:warn] [pid 886] AH00045: child process 892 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.530512 2023] [core:warn] [pid 886] AH00045: child process 23425 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577800 2023] [core:warn] [pid 886] AH00045: child process 29338 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577847 2023] [core:warn] [pid 886] AH00045: child process 5218 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577857 2023] [core:warn] [pid 886] AH00045: child process 29240 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577800 2023] [core:warn] [pid 886] AH00045: child process 29338 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577847 2023] [core:warn] [pid 886] AH00045: child process 5218 still did not exit, sending a SIGTERM
[Sun Apr 02 14:33:43.577857 2023] [core:warn] [pid 886] AH00045: child process 29240 still did not exit, sending a SIGTERM
인터넷에 검색을 하니 관련 설정값을 수정하라고 한다.
apachectl -M
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using jsshin-Mac-M1.local. Set the ‘ServerName’ directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_prefork_module (shared)
authn_file_module (shared)
….
mpm_prefork 모듈을 사용중이라서 extra/httpd-mpm.conf 파일의 설정값을 수정했다.
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>위와 같이 되어 있는 기본값을 아래와 같이 수정했다.
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 20
MaxRequestWorkers 500
MaxConnectionsPerChild 1000
</IfModule>
비록 서버자원을 많이사용할지는 몰라도 속도는 확실히 빨라졌다. 특히 검색결과가 빠르다.
<추가사항>
퍼온곳 : https://rumor1993.github.io/articles/2020-01/apache-MPM-(prefork,worker)
Prefork 방식
Prefork 방식은 자식프로세스가 싱글쓰레드로 동작한다고 합니다. 클라이언트로 요청을 받게 되면 하나의 프로세스가 이를 처리하는 방식을 말합니다 한 자식 프로세스당 하나의 쓰레드를 사용하는 방식을 PreFork라고 하는데 이 방식은 안정적인편이라서 아파치의 기본설정값으로 설정이 되어집니다. 아무래도 요청당 하나의 프로세스가 이를 처리하기 때문에 안정성이 높아 집니다 하지만 PreFork 방식은 Worker 방식보다 자원을 많이 사용하는 단점이 있습니다 즉, 동시접속자 많아진다면 Worker 방식에 비해 많은 자원을 사용하게 됩니다
worker 방식
Worker 방식은 자식 프로세스가 멀티 쓰레드로 동작한다고 합니다. 클라이언트로 요청을 받게 되면 프로세스가 이를 처리하는 PreFork와 달리 하나의 쓰레드가 처리하는 방식 입니다. 한 자식의 프로세스당 여러 개의 쓰레드를 가지고 있기 때문에 Worker 방식이 Prefork보다 메모리를 적게 사용하는 장점을 가지게 됩니다. 그래서 동시접속자를 처리하는데 유리합니다. 또한 스레드간에 메모리를 공유하고 있다고 하네요
// PreFork 방식
# /usr/local/apache/conf/extra/httpd-mpm.conf
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 300
ServerLimit 300
MaxConnectionsPerChild 0
</IfModule>
- startServer : 아파치서버의 자식프로새스 개수를 지정합니다
- MinSpareServers : 서버 프로세스의 최소 수, MinSpareServers가 유휴 상태보다 적은 경우 부모 프로세스는 새 자식 프로세스를 생성합니다
- MaxSpareServers : 서버 프로세스의 최대 수, MaxSpareServers가 유휴 상태보다 큰 경우 부모 프로세스가 초과되는 프로세스를 중지 시킵니다.
- MaxRequestWorkers, ServerLimit : 기본값이 256 이기 때문에 MaxRequestWorkers 값이 256보다 작으면 따로 적을 필요가 없으며, 256보다 크면 그와 같은 값으로 설정해야합니다.
- MaxRequestPerChild : 클라이언트들의 요청 개수를 제한합니다. 자식 프로세스가 이 값 만큼의 클라이언트 요청을 받았다면 이 자식 프로세스는 자동으로 Kill이 됩니다 (0은 무한대)
