Apache MPM 설정으로 Apache 동시접속자 대응용 성능튜닝하기
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 6,637 조회
- 0 추천
- 목록
본문
Apache MPM 설정으로 Apache 동시접속자 대응용 성능튜닝하기
웹서버를 운영하다 보면, 웹사이트 동시접속자수가 너무 높아져서 웹서버 장애가 발생하는 경우가 있다.
이경우 관리자가 할 수 있는 방법은
- 현재서버의 하드웨어 스펙을 높이는 방법
- 아파치 컴파일옵션을 최적화하여 재 설치하는 방법
- 웹서버를 여러대 증설하여 Load Banlancing으로 부하를 분산하는 방법
- 현재 설치된 아파치의 설정값을 최적화하는 방법
위의 방법들 가운데 가장 빠르게 응급조치할 수 있는 마지막 방법에 대해서 알아보고자 한다.
나머지 위의 방법들은 전부 시간, 비용이 많이 드는 경우이므로 이는 일정기간 계획하게 해야하는 경우이다.
하지만, 마지막 방법은 지금 설치되어 있는 아파치웹서버를 대상으로 지금 당장 할 수 있는 방법으로 비용면에서도 가장 저렴하다.
이 방법은 응급조치에 그칠 수도 있지만 경우에 따라서는 비용부담없이 간단한게 조치할 수 있는 방법이기 때문이다.
1. 커널 최대 사용 개수 설정
sysctl 값 설정으로 현재 실행상황의 커널파라미터값을 설정할 수 있다.
이 값을 설정함으로써 현재 운영중인 커널의 성능을 조절할 수 있다.
sysctl로 설정할 수 있는 커널파라미터 값중에 file-max라는 설정자는 커널이 동시에 오픈하여 사용할 수 있는 파일의 최대수를 의미한다.
sysctl관련 시스템파일들
/proc/sys /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf |
sysctl 파라미터들 확인하기
[root@sulinux01 ~]# sysctl -a abi.vsyscall32 = 1 crypto.fips_enabled = 0 crypto.fips_name = Rocky Linux 9 - Kernel Cryptographic API crypto.fips_version = 5.14.0-162.23.1.el9_1.x86_64 debug.exception-trace = 1 debug.kprobes-optimization = 1 dev.cdrom.autoclose = 1 dev.cdrom.autoeject = 0 dev.cdrom.check_media = 0 dev.cdrom.debug = 0 dev.cdrom.info = CD-ROM information, Id: cdrom.c 3.20 2003/12/17 dev.cdrom.info = dev.cdrom.info = drive name: sr0 dev.cdrom.info = drive speed: 32 dev.cdrom.info = drive # of slots: 1 dev.cdrom.info = Can close tray: 1 dev.cdrom.info = Can open tray: 1 dev.cdrom.info = Can lock tray: 1 이하생략 |
위의 예에서 보듯이 sysctl파라미터들은 너무 많다.
아래는 sysctl파라미터 개수를 확인한 것이다. 1130개의 파라미터 개수가 있다.
[root@sulinux01 ~]# sysctl -a | wc -l 1130 [root@sulinux01 ~]# |
아래는 이 값들 중에 file-max 값을 확인한 것이다.
[root@sulinux01 ~]# sysctl -a | grep file-max fs.file-max = 9223372036854775807 [root@sulinux01 ~]# |
이 값이 낮을 경우에 문제가 될 수 있다. 만약 이 값을 수정하고자 한다면 다음과 같이 한다.
[root@sulinux01 ~]# echo "fs.file-max=92233720368547758070" | tee -a /etc/sysctl.conf fs.file-max=92233720368547758070 [root@sulinux01 ~]# |
2. 프로세스당 사용할 수 있는 파일갯수 설정
실행되어 있는 프로세스들은 동시에 오픈하여 사용할 수 있는 파일갯수에 제한이 되어있다.
이 제한 설정은 ulimit으로 확인하고 또한 설정할 수 있다.
[root@sulinux01 ~]# ulimit -a real-time non-blocking time (microseconds, -R) unlimited core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7622 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024
pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited file locks (-x) unlimited [root@sulinux01 ~]# |
위의 예에서 보면 “open files” 값과 “max user processes” 값을 다음과 같이 설정하면 된다.
[root@sulinux01 ~]# ulimit -SHn 655360 [root@sulinux01 ~]# [root@sulinux01 ~]# ulimit -SHu 655360 [root@sulinux01 ~]# |
위와 같이 설정한 후 다시한번 확인한 것이다.
[root@sulinux01 ~]# ulimit -a | grep files open files (-n) 655360 [root@sulinux01 ~]# [root@sulinux01 ~]# ulimit -a | grep processes max user processes (-u) 655360 [root@sulinux01 ~]# |
위의 설정값은 Hard limit값과 Soft Limit값을 각각 설정한 것으로 앞에서 설정한 커널파라미터값인 fs.file-max 값보다 작아야한다.
왜냐하면 커널위에서 운영되고 있는 각각의 프로세스들은 커널의 설정값에 종속되기 때문이다.
지금까지의 설정은 모두 현재 운영상태의 값들을 변경한 것이다. 시스템이 부팅후에도 계속 이 설정이 적용되도록 하려면 다음과 같이 설정한다.
[root@sulinux01 ~]# ls -l /etc/security/limits.conf -rw-r--r--. 1 root root 2426 10월 31 2022 /etc/security/limits.conf [root@sulinux01 ~]# |
위의 파일은 부팅시 마다 적용되는 적용되는 값들을 설정해두는 파일이다.
* soft nofile 655360 * hard nofile 655360 * soft nproc 655360 * hard nproc 655360 |
3. Apache 설정값 조정
Apache 웹서버는 다중처리모듈인 MPM(Multi-Processing Modules)을 이용하여 외부요청을 처리한다.
MPM을 설정을 이용하여 아파치웹서버가 외부요청을 어떻게 처리할 것인가를 결정하는데 이 MPM방식에는 다음과 같이 3가지가 있다.
아파치 다중처리모듈(MPM)에 대한 가장 자세한 설명을 보려면 아래 URL을 확인해보기 바란다.
https://httpd.apache.org/docs/2.4/mpm.html
방법1. prefork
Non-thread방식으로 미리 여러 개의 프로세스를 생성해두고 하나의 프로세스가 하나의 요청을 처리하는 방식이다.
방법2. worker
Multi-thread 방식으로 하나의 프로세스에 의해 생성된 여러 스레스들이 각각의 요청을 처리하는 방식이다. 동시접속자가 높은 경우에 유리하다.
방법3. Event
방법2번인 worker방식을 기반으로 하지만 외부요청을 분산하는 스레드를 별도로 두어 지연처리를 최소화하는 방법이다. 속도가 가장 빠르고 동시접속자가 많은 경우에 유용하다.
4. 아파치 실행 상황 파악하기
아파치웹서버의 버전과 MPM 설정과 컴파일시 사용옵션등을 확인하기 위해서는 “httpd -V”를 실행해 본다.
[root@sulinux01 ~]# httpd -V Server version: Apache/2.4.53 (Rocky Linux) Server built: Mar 16 2023 00:00:00 Server's Module Magic Number: 20120211:124 Server loaded: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.44 2020-02-12 Compiled using: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.44 2020-02-12 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_PROC_PTHREAD_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="run/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf" [root@sulinux01 ~]# |
이 값들 중에 원하는 MPM설정을 확인하려면 다음과 같이 확인한다.
[root@sulinux01 ~]# httpd -V | grep MPM Server MPM: prefork [root@sulinux01 ~]# |
위에서 확인한 바와 같이 현재 실행중인 아파치의 MPM값은 prefork이다.
5. 아파치 MPM 설정 변경하기
아파치의 MPM 값을 변경하고자 한다면 아래 파일에서 설정을 할 수 있다.
[root@sulinux01 ~]# ls -l /etc/httpd/conf.modules.d/00-mpm.conf -rw-r--r-- 1 root root 1164 5월 22 13:17 /etc/httpd/conf.modules.d/00-mpm.conf [root@sulinux01 ~]# |
원하는 MPM설정으로 변경하고자 한다면 주석처리하고 주석제거함으로써 설정할 수 있다.
[root@sulinux01 ~]# cat /etc/httpd/conf.modules.d/00-mpm.conf | grep modules LoadModule mpm_prefork_module modules/mod_mpm_prefork.so #LoadModule mpm_worker_module modules/mod_mpm_worker.so #LoadModule mpm_event_module modules/mod_mpm_event.so [root@sulinux01 ~]# |
prefork로 설정했다면 그 아래에 다음과 같은 prefork 적용에 대한 세부설정을 추가 할 수 있다.
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
<IfModule mpm_prefork_module> ServerLimit 1024 StartServers 5 MaxClients 1024 MinSpareServers 5 MaxSpareServers 10 MaxRequestPerChild 1024 </IfModule> |
참고로 위의 설정값에 대한 간략한 의미이다.
ServerLimit 1024 아파치가 생성가능한 프로세스의 최대수. MaxRequestWorkers보다 커야함
StartServers 5 아파치실행시에 실행될 자식프로세스수
MaxClients 1024 동시접속자수의 최대값으로 MaxRequestWorkers값 같은의미
MinSpareServers 5 요청이 없어도 유지할 프로세스수의 최소값
MaxSpareServers 10 요청이 없어도 유지할 프로세스수의 최대값
MaxRequestsPerChild 1024 각각의 자식프로세스가 최대 몇 개까지 처리하고 종료할 것인지의 설정값이며 이는
MaxConnectionsPerChild값과 동일한 의미이다. 이 값이 0이면 자식프로세스가 종료되지 않고 계속 요청에 대한 처리를 하게 된다.
위와 같이 설정했다면 혹시 오타등으로 인하여 설정값에 문제가 없는지 구문에 이상이 없는가를 확인하기 위하여 다음과 같이 확인한다.
[root@sulinux01 ~]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.19.201. Set the 'ServerName' directive globally to suppress this message Syntax OK [root@sulinux01 ~]# |
이상이 없다면 설정한 값을 적용하기 위하여 아파치를 재시작 한다.
[root@sulinux01 ~]# systemctl restart httpd [root@sulinux01 ~]# [root@sulinux01 ~]# ps -ef | grep httpd root 5500 1 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5501 5500 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5502 5500 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5503 5500 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5504 5500 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5505 5500 0 16:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 5548 2271 0 16:13 pts/0 00:00:00 grep --color=auto httpd [root@sulinux01 ~]# |
6. 아파치 튜닝값 성능테스트
먼저 다음과 같이 아파치웹서버를 재시작한다.
[root@sulinux01 ~]# systemctl restart httpd [root@sulinux01 ~]# |
그런다음 아파치프로세스를 실행중임을 확인한다.
[root@sulinux01 ~]# ps -ef | grep httpd root 9860 1 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9861 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9862 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9863 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9864 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9865 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 9913 9860 0 16:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 9945 2271 0 16:44 pts/0 00:00:00 grep --color=auto httpd [root@sulinux01 ~]# |
다른 터미널을 열어서(또는 다른 리눅스서버에서) ab 툴을 이용하여 다음과 같은 대규모 웹요청을 발생시킨다.
[root@sulinux01 ~]# ab -n 90000 -c 100 http://192.168.19.201/index.html This is ApacheBench, Version 2.3 <$Revision: 1879490 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.19.201 (be patient) |
위와같이 요청을 발생시킨 후에 아파치웹서버의 프로세스 개수가 어떻게 변화되는가를 확인해 본다.
[root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 5 [root@sulinux01 ~]# [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 12 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 36 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 65 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 71 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 83 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 99 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 105 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 105 [root@sulinux01 ~]# ps -ef | grep httpd | grep -v root | grep -v auto | wc -l 105 [root@sulinux01 ~]# |
이상과 같이 아파치 웹서버의 모듈설정값으로 아파치웹서버의 간단한 성능튜닝하는 방법을 알아 보았다.
관련자료
-
이전
-
다음