apache 工具和简单优化

压力测试工具 ab.exe 用来测试网站并发量大小和某个页面访问时间

ab.exe –n 访问的总次数 –c  有多少人访问(并发量) 访问的页面url

举例说明:

ab.exe –n 10000 –c 100 http://web.com/test/demo.php

结果:
Server Software: Apache/2.2.22
Server Hostname: web.com
Server Port: 80

Document Path: /test/demo.php
Document Length: 1100 bytes

Concurrency Level: 100
Time taken for tests: 71.792 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 12880000 bytes
HTML transferred: 11000000 bytes
Requests per second: 139.29 [#/sec] (mean)
Time per request: 717.921 [ms] (mean)
Time per request: 7.179 [ms] (mean, across all concurrent requests) 单人获取请求时间 数据越小 服务越好
Transfer rate: 175.20 [Kbytes/sec] received

调整并发量
MPM (多路处理模块, 即 apache采用怎样的方式来处理并发.), 主要有三种方式

  1. perfork 预处理进程方式  预先开启一些进程,等待并发需求,进程提供服务,消耗比较大
  2. worker 工作模式  预先开启一些进程,等待并发需求,由进程划分线程,线程提供服务,消耗小
  3. winnt  这个一般说是windows采用的 等同与工作模式,仅用win平台

 如何设置我们的apache的最大并发数 ,步骤如下:
查看apache MPM模式 http.exe -l ;启用httpd-mpm.conf 扩展设置,修改对应模式的ThreadsPerChild值;重启apache

一般linux下,采用的MPM是 perfork模式

<IfModule mpm_prefork_module>
StartServers 5 预先启用的进程
MinSpareServers 5 最小空闲进程
MaxSpareServers 10 最大空闲进程
MaxClients 150 最大并发量 一般最大几千左右 所以大型网站全部使用集群
MaxRequestsPerChild 0 每个进程配多少线程
</IfModule>

建议配置
中型网站

<IfModule mpm_prefork_module>
              StartServers         5      #预先启动
              MinSpareServers      5
              MaxSpareServers      10  #最大空闲进程
              ServerLimit          1500   #用于修改apache编程参数
              MaxClients           1000   #最大并发数
              MaxRequestsPerChild  0

</IfModule>
网站PV百万

ServerLimit          2500   #用于修改apache编程参数
MaxClients           2000   #最大并发数

原文地址:https://www.cnblogs.com/caps/p/2941752.html