[Tomcat] server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

개발할래·2023년 11월 2일
0

개발

목록 보기
8/14

MPM?

Apache MPM은 Multi Processing Module의 약자로 Apache가 받아들인 요청을 처리하기 위해 자식 proccess 에 분배하는 방식

MPM 종류

PREFORK

Prefork 방식은 하나의 요청에 하나의 웹서버 프로세스를 할당하여 처리하는 방식, 실행중인 프로세스를 fork를 이용해 복제하여 실행 -> 다른 여러 모듈을 사용하는 호환성이 좋음

프로세스가 소비하는 메모리가 많아서 요청이 급증하면 메모리 부족할 가능성이 있음

WORKER

Worker 방식은 요청을 스레드 단위로 처리
기본 사용 메모리가 Prefork 방식보다 낮으며 스레드 간 메모리를 서로 굥유

EVENT

Event 방식은 Worker에 기반하면서 한 단계 더 나아간 방법

Worker의 방식의 경우, Keep alive시에 클라이언트로부터 요청을 기다리고 있는 자식 프로세스 혹은 스레드 전체를 keep 하게 됩니다.
Event 방식은 각 프로세스르 위한 전용 리스너 스레드를 따로 둠으로서 해당 문제를 해결

✅ 오류 발생

[Tue Oct 24 09:03:20.239744 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18798 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:20.239805 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18799 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:20.239817 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18882 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:20.239824 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 19022 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:20.239830 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 22771 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:22.241953 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18798 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:22.241992 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18799 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:22.242001 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 19022 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:22.242005 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 22771 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:24.244067 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18798 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:24.244106 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 18799 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:24.244111 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 19022 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:24.244120 2023] [core:warn] [pid 18796:tid 139869913864000] AH00045: child process 22771 still did not exit, sending a SIGTERM
[Tue Oct 24 09:03:26.246189 2023] [core:error] [pid 18796:tid 139869913864000] AH00046: child process 18798 still did not exit, sending a SIGKILL
[Tue Oct 24 09:03:26.246229 2023] [core:error] [pid 18796:tid 139869913864000] AH00046: child process 18799 still did not exit, sending a SIGKILL
[Tue Oct 24 09:03:26.246236 2023] [core:error] [pid 18796:tid 139869913864000] AH00046: child process 19022 still did not exit, sending a SIGKILL
[Tue Oct 24 09:03:26.246246 2023] [core:error] [pid 18796:tid 139869913864000] AH00046: child process 22771 still did not exit, sending a SIGKILL
[Tue Oct 24 09:03:27.247566 2023] [mpm_event:notice] [pid 18796:tid 139869913864000] AH00491: caught SIGTERM, shutting down
[Tue Oct 24 09:03:34.687388 2023] [ssl:warn] [pid 24611:tid 139730549753664] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Tue Oct 24 09:03:34.689517 2023] [mpm_event:notice] [pid 24611:tid 139730549753664] AH00489: Apache/2.4.54 (Unix) OpenSSL/1.1.1s mod_jk/1.2.48 configured -- resuming normal operations
[Tue Oct 24 09:03:34.689548 2023] [core:notice] [pid 24611:tid 139730549753664] AH00094: Command line: '/apps/apache/bin/httpd'
[Tue Oct 24 10:55:07.158432 2023] [mpm_event:error] [pid 24611:tid 139730549753664] AH10159: server is within MinSpareThreads of MaxRequestWorkers, considerg the MaxRequestWorkers setting raisin
[Tue Oct 24 10:55:24.176156 2023] [mpm_event:error] [pid 24611:tid 139730549753664] AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

✅ MPM 튜닝

MPM 확인

# http -v

httpd-mpm.conf 설정

<IfModule mpm_event_module>
    StartServers            5	# 시작시에 생성되는 서버 프로세스의 개수, 자식 프로세스의 수는 부하에 따라 동적으로 변경되기 때문에 이 값은 큰 의미가 없습니다.(Default : 3)
    ServerLimit            32   # 프로세스의 최대 수
    MaxRequestWorkers      4096 # 최대 동시 접속자 수(ServerLimit x ThreadsPerChild)
    MinSpareThreads         64	# 최소 thread 개수, 서버에 idle 쓰레드가 충분하지 않다면 child 프로세스는 idle 쓰레드가 MinSpareThreads 보다 커질때까지 생성됩니다.(Default : 75)
    MaxSpareThreads        128	# 최대 thread개수, 서버에 너무 많은 idle 쓰레드가 존재하면 child 프로세스는 idle 쓰레드가 MaxSpareThreads 수보다 작아질 때까지 kill 됩니다.(Default : 250)
    ThreadsPerChild        128	# 개별 자식 프로세스가 지속적으로 가질 수 있는 Thread의 개수
    MaxConnectionsPerChild   0	# 자식 프로세스가 서비스할 수 있는 최대 요청 개수
</IfModule>

http.conf

# 지정한 시간동안 클라이언트가 응답이 없을 경우, 세션을 끊어 버립니다
Timeout 60

# 지속적인 연결을 허용 여부를 설정
KeepAlive on

# 허용할 최대 요청 수를 지정합니다. 최상의 성능을 위해서는 수치를 높게 설정하는 것을 권장합니다.
# 무제한으로 설정하려면 0으로 설정하면 됩니다.
MaxKeepAliveRequests 100

# 동일한 연결에서 동일한 클라이언트의 다음 요청을 대기하는 시간입니다.
# 응답이 없을 경우 서버가 클라이언트의 접속을 끊습니다.
KeepAliveTimeout 5

현재 동시 접속자 확인

# netstat -nltp |grep :80.*ESTABLISHED |wc -l

벤치마킹 테스트

 # ab -n 4000 -c 400 http://localhost/

-n은 요청수를, -c 는 동시요청수를 나타낸다.

400명의 사용자가 10번씩 총 4000번 요청하는 것입니다.

사이트 주소의 끝에 / (슬래시)를 붙여야 합니다.

메모리 사용률

- 전체 메모리 사용량을 아파치 프로세스 개수로 나누어 계산



1) Event 방식

[root@localhost ~]# ps aux | grep apache | awk '{print $6}' | awk '{total = total + $1} END {print total/1024}'

26.8359
profile
내 인생부터 개발

0개의 댓글