文件路径
D:\AppServ\Apache2.2\bin\ab.exe
windows下,cmd打开dos命令窗口.
> ab.exe -h 查看帮助信息
使用方式:
ab.exe [options] [http://]hostname[:port]/path
常用参数:
-n 请求 执行请求数
-c 并发 并发数
-t 时间限制 等待响应的最长时间,单位:秒
-w 把结果打印到html
-i 用 HEAD 代替 GET 发请求
-C 属性 添加cookie, eg. 'Apache=1234. (可重复)
-H 属性 添加头信息,插入到所有头信息之后.eg. 'Accept-Encoding: gzip'
-X 代理:端口 使用代理
-V 版本信息
-k 使用 HTTP KeepAlive 特性
-h 帮助信息
> ab.exe -n 10 -c 10 http://www.baidu.com/
测试结果
Server Software: BWS/1.0
Server Hostname: www.baidu.com
Server Port: 80
Document Path: /
Document Length: 10480 bytes
Concurrency Level: 10 #并发数
Time taken for tests: 0.60008 seconds #总耗时
Complete requests: 10 #完成请求数
Failed requests: 8 #失败请求
(Connect: 0, Length: 8, Exceptions: 0)
Write errors: 0
Total transferred: 109644 bytes
HTML transferred: 104700 bytes
Requests per second: 166.64 [#/sec] (mean) #每秒请求数
Time per request: 60.008 [ms] (mean) #每次请求耗时
Time per request: 6.001 [ms] (mean, across all concurrent requests)
Transfer rate: 1783.10 [Kbytes/sec] received #传输速率
ab.exe 使用注意事项:
1. -c 并发数不能大于 -n 请求数,否则会报错
2. 最大并发数在配置文件中可修改,修改方法如下
查看工作模式
cmd打开dos指令窗口
cd 到D:\AppServ\Apache2.2\bin\下,执行指令
> httpd -l //查看配置文件使用的工作模式
结果是:
mpm_winnt.c //即使用的是winnt模式, mpm :多路处理模块
配置工作模式
打开D:\AppServ\Apache2.2\conf\http.conf文件,查找mpm,找到
# Server-pool management (MPM specific)
# Include conf/extra/httpd-mpm.conf
去掉第二行前的注释符,即启用httpd-mpm.conf文件
找到D:\AppServ\Apache2.2\conf\extra\下的httpd-mpm.conf文件,打开并查找WinNT,找到
# WinNT MPM #windows模式
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt_module>
ThreadsPerChild 150
MaxRequestsPerChild 0
</IfModule>
ThreadsPerChild 子线程,即并发数,将150改为1000
其他工作模式
prefork MPM #预处理进程模式 用进程处理请求
<IfModule mpm_prefork_module>
StartServers 5 #预先分配进程个数
MinSpareServers 5 #最小空闲进程
MaxSpareServers 10 #最大空闲进程
MaxClients 150 #支持的最大并发数
MaxRequestsPerChild 0
</IfModule>
linux下默认采用工作方式,用预先分配子进程的方式处理请求,进程之间相互独立,是最稳定的MPM之一
worker MPM #工作模式 用线程处理请求,线程即子进程
<IfModule mpm_worker_module>
StartServers 2 #初始进程数
MaxClients 150 #支持的最大并发数
MinSpareThreads 25 #最小空闲线程
MaxSpareThreads 75 #最大空闲线程
ThreadsPerChild 25 #一个进程包含的线程数
MaxRequestsPerChild 0 #最大请求子线程,设置为0即执行完之后,进程不死,设置为10,执行完之后,进程死掉
</IfModule>
worker模式采用多进程多线程,稳定,是apache 2.x的发展趋势
没有评论:
发表评论