欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

使用Apache ab进行http性能测试

程序员文章站 2023-09-09 19:39:06
mac自带了apache环境 打开“终端(terminal)”,输入 sudo apachectl -v,(可能需要输入机器秘密)。如下显示apache的版本 接着输入 sud...

mac自带了apache环境

打开“终端(terminal)”,输入 sudo apachectl -v,(可能需要输入机器秘密)。如下显示apache的版本

使用Apache ab进行http性能测试

接着输入 sudo apachectl start,这样apache就启动了。打开safari浏览器地址栏输入 “http://localhost”,可以看到内容为“it works!”的页面。其位于“/library(资源库)/webserver/documents/”下,这就是apache的默认根目录。

apache的安装目录在:/etc/apache2/,etc默认是隐藏的。有三种方式查看:

1、dock下右键finder,选择"前往文件夹",输入"/etc"
2、在finder下----》前往---》前往文件夹,然后输入/etc
3、可以在terminal 输入 "open /etc"

windows可以去http://httpd.apache.org/download.cgi下载,或者从命令行安装

1. 安装apache

     sudo port install apache2

启动apache: sudo apachectl start

2.  brew install pcre

3. wget http://ftp.yz.yamagata-u.ac.jp/pub/network/apache//httpd/httpd-2.4.4.tar.bz2

   (1)解压
   (2) ./configure
   (3) make && make install
   (4) sudo cp support/ab /usr/sbin  

4. ab -n 1000 -c 10 http://localhost:3000/  最后这个斜杠不能少

这个ab -n1000 -c10 http://localhost:3000/命令,在window系统下,需要先用cd命令定位到你的apache安装目录的bin文件夹。。。 

ab的参数说明

-n  需要执行的请求次数

-c  并发的数量

-t   等待返回的最长时间

-b  tcp收发缓冲区的大小,单位(byte)

-p 使用post (同时需要定义-t参数)

-u 使用put (同时需要定义-t参数)

-t content-type, 例如application/x-www-form-urlencoded, 默认为text/plain

-w 把结果打印在html的表格里

-x  表格的属性

-y  tr行属性

-z  td列属性

-c 设置cookie 例如apach=1234

-h header行, 例如accept-encoding:gzip

-k 是否标示位http keep alive

测试结果:

this is apachebench, version 2.3 <$revision: 1663405 $>
copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/

benchmarking localhost (be patient)
completed 100 requests
completed 200 requests
completed 300 requests
completed 400 requests
completed 500 requests
completed 600 requests
completed 700 requests
completed 800 requests
completed 900 requests
completed 1000 requests
finished 1000 requests


server software:  
server hostname:  localhost
server port:   3000

document path:   /
document length:  14 bytes

concurrency level:  10
time taken for tests: 0.323 seconds
complete requests:  1000
failed requests:  0
total transferred:  115000 bytes
html transferred:  14000 bytes
requests per second: 3097.37 [#/sec] (mean)
time per request:  3.229 [ms] (mean)
time per request:  0.323 [ms] (mean, across all concurrent requests)
transfer rate:   347.85 [kbytes/sec] received

connection times (ms)
    min mean[+/-sd] median max
connect:  0 0 0.1  0  1
processing:  1 3 2.2  2  16
waiting:  1 3 2.2  2  16
total:   1 3 2.2  2  16

percentage of the requests served within a certain time (ms)
 50%  2
 66%  3
 75%  3
 80%  4
 90%  5
 95%  7
 98%  13
 99%  15
 100%  16 (longest request)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。