아파치 웹서버 성능검사 도구
리눅스에서 웹서버 벤치마크(스트레스) 테스트 명령어 ab 라는 툴이 있습니다.
웹서버의 성능 및 예상하는 동시접속자 수를 버틸 수 있는지 테스트 하는데 사용되며 튜닝에 이용되기도 합니다.
ab 명령어가 없다고 나오면 아래와 같이 설치하면 됩니다.
[root@virtualbox ~]# yum install httpd-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.navercorp.com
* epel: mirror.premi.st
* extras: mirror.navercorp.com
* updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos will be installed
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-tools-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-tools-2.4.6-40.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd-tools x86_64 2.4.6-40.el7.centos base 82 k
Installing for dependencies:
apr x86_64 1.4.8-3.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
Transaction Summary
================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 277 k
Installed size: 584 k
Is this ok [y/d/N]: y
Downloading packages:
(1/3): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00
(2/3): httpd-tools-2.4.6-40.el7.centos.x86_64.rpm | 82 kB 00:00
(3/3): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:20
--------------------------------------------------------------------------------
Total 13 kB/s | 277 kB 00:20
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/3
Installing : apr-util-1.5.2-6.el7.x86_64 2/3
Installing : httpd-tools-2.4.6-40.el7.centos.x86_64 3/3
Verifying : apr-util-1.5.2-6.el7.x86_64 1/3
Verifying : httpd-tools-2.4.6-40.el7.centos.x86_64 2/3
Verifying : apr-1.4.8-3.el7.x86_64 3/3
Installed:
httpd-tools.x86_64 0:2.4.6-40.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
Complete!
테스트 방법은 아래와 같습니다.
[root@virtualbox ~]# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking conoha.ivps.kr (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Apache/2.4.6
Server Hostname: conoha.ivps.kr
Server Port: 80
Document Path: /phpinfo.php
Document Length: 91191 bytes
Concurrency Level: 20
Time taken for tests: 10.072 seconds
Complete requests: 500
Failed requests: 55
(Connect: 0, Receive: 0, Length: 55, Exceptions: 0)
Write errors: 0
Total transferred: 45704945 bytes
HTML transferred: 45595445 bytes
Requests per second: 49.64 [#/sec] (mean)
Time per request: 402.864 [ms] (mean)
Time per request: 20.143 [ms] (mean, across all concurrent requests)
Transfer rate: 4431.65 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 65 87 13.5 93 125
Processing: 207 300 88.0 296 805
Waiting: 66 107 48.5 96 304
Total: 276 387 94.9 392 905
Percentage of the requests served within a certain time (ms)
50% 392
66% 401
75% 411
80% 422
90% 489
95% 551
98% 691
99% 735
100% 905 (longest request)
500번 요청해서 55번 실패했다는 로그입니다.
▶ 옵션설명
-c 옵션 : 동시 요청수 (아래의 -n 횟수 보다 이하의 수여야 한다.)
-n 옵션 : 요청 횟수
# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php
동시에 20명이 요청하는데 합산해서 요청 수가 500 이라는 의미 ( 20 x 25 = 500 )
-c 5 -n 100 : 5 x 20 = 100
-c 100 -n 100 : 100 x 1 = 100
-c 3 -n 100 : 3 x 33 + 1 = 100
이제 아파치 튜닝중 하나인 mod_cache 모듈을 활용해서 cache 기능을 활성화 시켜서 테스트 해보도록 하겠습니다.
▶아파치 mod_cache 기능
아파치 2.2.x 버전은 두번째 줄에 아마도 mod_disk_cache.c 로 해주어야 합니다.
아래는 2.4.x 버전용인데 차이는 mod_disk_cache 이냐 mod_cache_disk 이냐 입니다.
아래의 내용을 /etc/httpd/conf/httpd.conf 파일에 추가해주던지 아니면
/etc/httpd/conf.d/cache.conf 파일을 신규로 생성해서 저장해 주면 됩니다.
<IfModule mod_cache.c>
<IfModule mod_cache_disk.c>
CacheEnable disk /
CacheRoot /var/cache/mod_cache/tmp
CacheDirLevels 2
CacheDirLength 1
CacheMaxFileSize 300000
CacheMinFileSize 1
#CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheIgnoreQueryString Off
CacheIgnoreHeaders None
CacheLastModifiedFactor 0.1
CacheDefaultExpire 300
CacheMaxExpire 86400
#CacheStoreNoStore On
#CacheStorePrivate On
</IfModule>
</IfModule>
이제는 위에 지정한 /var/cache/mod_cache/tmp 폴더를 만들어 줍니다. 물론 apache 접근 권한이 가능한 경로라면 자동으로 만들어집니다.
[root@conoha conf.d]# cd /var/cache
[root@conoha cache]# ll
total 4
drwx------ 2 root root 22 Apr 7 11:01 ldconfig
drwxr-xr-x 34 root root 4096 Apr 7 03:33 man
drwxr-xr-x 3 root root 19 Apr 7 10:36 yum
[root@conoha cache]# mkdir -m700 mod_cache
[root@conoha cache]# mkdir -m700 mod_cache/tmp
[root@conoha cache]# chown -R apache.apache mod_cache
디렉토리를 생성해 주었다면 이제는 아파치를 재시작 해주고 테스트 하면 됩니다.
아파치 재시작은 CentOS 6.x 버전은 service httpd restart
7.x 버전은 systemctl restart httpd.service
[root@virtualbox ~]# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking conoha.ivps.kr (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Apache/2.4.6
Server Hostname: conoha.ivps.kr
Server Port: 80
Document Path: /phpinfo.php
Document Length: 91191 bytes
Concurrency Level: 20
Time taken for tests: 17.398 seconds
Complete requests: 500
Failed requests: 2
(Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors: 0
Total transferred: 45720566 bytes
HTML transferred: 45595498 bytes
Requests per second: 28.74 [#/sec] (mean)
Time per request: 695.910 [ms] (mean)
Time per request: 34.795 [ms] (mean, across all concurrent requests)
Transfer rate: 2566.37 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 64 86 66.6 77 1135
Processing: 405 589 253.8 564 2083
Waiting: 63 156 232.0 92 1496
Total: 472 675 266.6 658 2182
Percentage of the requests served within a certain time (ms)
50% 658
66% 669
75% 677
80% 690
90% 921
95% 1334
98% 1658
99% 1770
100% 2182 (longest request)
Failed requests 가 눈에 띄게 줄어들었습니다.
테스트 서버가 ConoHa VPS 서버인데다 램(1GB) 등 하드웨어 사양이 좀 딸려서 좀 더 심한 테스트를 하지 못한 점은 양해바랍니다.