AB 사용법 - Apache Benchmarking

 

ab는 "Apache HTTP server Benchmarking tool"의 약어로서 아파치 서버의 응답속도를 측정하는 벤치마킹툴이다.

도메인이나 특정 페이지의 응답속도를 측정할 수 있다.

 

 

$./ab -V
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/


 

$./ab -h

Usage: ./ab 【options】 【http://】hostname【:port】/path
Options are:
    -n requests  Number of requests to perform : 벤치마킹을 위한 요청수
    -c concurrency Number of multiple requests to make : 하나의 요청당 체크할 다중 요구수 (기본값 : 1)
    -t timelimit Seconds to max. wait for responses : 제한시간
    -p postfile  File containg data to POST : POST 할 파일 지정
    -T content-type Content-type header for POSTing
    -v verbosity    How much troubleshooting info to print : 자세한 헤더정보 출력 (유용함)
    -w              Print out results in HTML tables : HTML 형태로 출력 (유용함)
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234' (repeatable) : 쿠키 사용시
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: zop'
                       Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                       are a colon separated username and password. : 사용자 인증을 요하는 페이지 체크시 아이디:비밀번호
    -P attribute    Add Basic Proxy Authentication, the attributes
                       are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature : 하나의 세션을 맺은 상태에서 여러개의 요구가 하나의 세션으로 인식
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -h              Display usage information (this message)

 

실행방법은  ./ab "http 주소"

* 주의 : 여기서 주의해야 할것은 위와같이 도메인명만 입력할때는 뒤에 "/"를 꼭 붙여야 한다.

 

그럼 실제로 네이버의 응답속도를 체크해자.

출력되는 내용은 아래와 같다.

 

【】# ab http://www.naver.com/
This is ApacheBench, Version 1.3d <$Revision: 1.69 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.naver.com (be patient).....done


; 아파치 버전

Server Software:        Apache                                            


; 도메인명

Server Hostname:        www.naver.com


; 웹서비스 사용 포트

Server Port:            80

 

; 초기문서가 위치하는 웹문서 root(서버내의 절대경로가 아님)

Document Path:          /


; 초기문서의 용량

Document Length:        72226 bytes

 

Concurrency Level:      1


; 응답속도(사실 이값만 확인하면 된다.)

Time taken for tests:   0.016 seconds


; 요구에 응답한 세션수

Complete requests:      1


; 요구에 응답실패한 세션수

Failed requests:        0


; 실패한 에러수

Broken pipe errors:     0


; 총 전송 바이트수

Total transferred:      72539 bytes


; 총 전송한 HTML 바이트수

HTML transferred:       72226 bytes


; 초당 응답요구수

Requests per second:    62.50 【#/sec】 (mean)


; 요구에 응답한 시간 (이값도 중요하다)

Time per request:       16.00 【ms】 (mean)


; 요구에 응답한 시간

Time per request:       16.00 【ms】 (mean, across all concurrent requests)

; 초당 전송 가능한 용량

Transfer rate:          4533.69 【Kbytes/sec】 received

 

=> 응용

1. 1회의 전송을 믿지 못하겠다는 분은 여러번 시도하여 그에대한 평균치를 얻을수 있다.

  ab -n 1 http://www.naver.com/

 

2. 다중세션으로 벤치마킹하여 더욱 신뢰높은 값을 얻는 방법

 ab -c 30 http://www.naver.com/

 

3. 응답속도를 KeepAlive 속성을 활성화하여 테스트하기

 ab -k http://www.naver.com/

 

4. 측정 결과를 HTML 파일로 저장하기

 ab -n 1 -w http://www.naver.com/ > naver.com_test.htm

 

ab 명령어를 이용해서 조금 억지스럽지만 결과값으로 서버의 부하까지도 추측이 가능할 것이다.

 

* ab 실행파일은 아파치를 설치한 디렉토리/bin 에 있습니다.

<script>

// 오른쪽 마우스 금지 스크립트

$(document).ready(function() {

    $(document).bind("contextmenu", function(e){

       // alert("오른쪽 마우스 금지");

        return false;

    });

 

    $('img').bind("contextmenu",function(e){ 

       // alert("그림에서 오른쪽 마우스 금지"); 

        return false; 

    }); 

 

    $('img').bind("selectstart",function(e){ 

        //alert("그림에서 오른쪽 마우스 금지"); 

        return false;  

    }); 

}); 

 

document.oncontextmenu=function(){return false;} // 우클릭 방지

document.onselectstart=function(){return false;} // 선택 방지

document.ondragstart=function(){return false;} // 드래그 방지 

document.onmousedown=function(){return false;}  // 셀렉트 박스 방지

</script>



【root@www s_info】# more sinfo.php
<?
// ==================================================================
// Server Hardware Information
// ==================================================================
//

?>

<html>
<head>
<title>【 Server Information 】</title>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<STYLE type=text/css>
BODY { FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana,arial, helvetica, serif; margin : 0 0 0 0;}
</STYLE>
</head>
<body>
<pre>
<b>【Uptime】 :</b>
<? system("uptime"); ?>

<b>【System Information】 :</b>
<? system("uname -a"); ?>

<b>【O/S Name】 :</b>
<? system("cat /etc/issue"); ?>

<b>【CPU Information】 :</b>
<? system("cat /proc/cpuinfo | grep \"model name\\|processor\""); ?>

<b>【Memory Usage (MB)】 :</b>
<? system("free -m"); ?>

<b>【Disk Usage】 :</b>
<? system("df -h"); ?>

<b>【Network info】 :</b>
<? system("cat /etc/sysconfig/network | grep \"GATEWAY\""); ?>
<? system("cat /etc/sysconfig/network-scripts/ifcfg-* | grep \"DEVICE\\|IPADDR\\|NETMASK\\|GATEWAY\""); ?>

<b>【Pstree Usage】 :</b>
<? system("pstree -up"); ?>

</pre>

<br>
<br>
<center>
<font size="1">Copyright &copy; 2008 </font>
</center>
</body>
</html>

html>
<body>
<script type="text/javascript">
document.location.href="http://aaa.domain.com:81";
</script>
</body>
</html>

 

-----------------------------------------------------------------------------

 

<frameset rows="*" border="0">
<frame name="MAIN" scrolling="auto" marginwidth="0" marginheight="0" src="http://aaa.domain.com:81">
</frameset>

+ Recent posts