vps中数据高并发下的Apache优化配置

以下是我在度娘上搜集整理的解决办法,感谢网友的贡献与分享。

  1. 首先确定本机的apache是什么MPM模式(winnt模式,perfork模式,worker模式)

进入到apache/bin目录,输入cmd命令:httpd.exe -l如下所示:

vps中数据高并发下的Apache优化配置_第1张图片

看mpm_xxx.c 如果xxx是winnt  说明是winnt(windows环境),另外在Linux下还可能是perfork或者worker

2.利用apache自带的ab工具,进行优化前的压力测试

说明:Apache的ab命令模拟多线程并发请求,测试服务器负载压力,也可以测试nginx、lighthttp、IIS等其它Web服务。

在Windows系统下,打开cmd命令行窗口,定位到apache安装目录的bin目录下

   键入命令:
ab -n 800 -c 800  http://192.168.0.10/
(-n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url)

ab -t 60 -c 100 http://192.168.0.10/
在60秒内发请求,一次100个请求。 
//如果需要在url中带参数,这样做
ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello.html
p.txt 是和ab.exe在一个目录
p.txt 中可以写参数,如  p=wdp&fq=78
结果参数解释:
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.10 (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
Finished 800 requests
Server Software:        Microsoft-HTTPAPI/2.0
Server Hostname:        192.168.0.10
Server Port:            80

Document Path:          /
Document Length:        315 bytes       HTTP响应数据的正文长度

Concurrency Level:      800
Time taken for tests:   0.914 seconds    所有这些请求处理完成所花费的时间
Complete requests:      800             完成请求数
Failed requests:        0                失败请求数
Write errors:           0               
Non-2xx responses:      800
Total transferred:      393600 bytes     网络总传输量
HTML transferred:       252000 bytes     HTML内容传输量
Requests per second:    875.22 [#/sec] (mean) 吞吐量-每秒请求数
Time per request:       914.052 [ms] (mean)  服务器收到请求,响应页面要花费的时间
Time per request:       1.143 [ms] (mean, across all concurrent requests) 并发的每个请求平均消耗时间
Transfer rate:          420.52 [Kbytes/sec] received 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

3. 进行Apache优化配置

(1)若在windows系统下

修改httpd-mpm.conf文件

# WinNT MPM

# 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>

(2)若在Linux系统下,一般采用的MPM是perfork模式

<IfModule mpm_prefork_module>

StartServers          5        //预先起5个进程

MinSpareServers       5       //最小空闲进程

MaxSpareServers      10      //最大空闲进程

MaxClients          150      //并发连接数

MaxRequestsPerChild   0      //指一个进程里可以起多少个线程,对worker更好,0为不限制

</IfModule>

给大家一个合理的建议配置,对在部分网站,中型网站,配置:

<IfModule mpm_prefork_module>

StartServers          5        //预先起5个进程

MinSpareServers       5       //最小空闲进程

MaxSpareServers      10      //最大空闲进程

ServerLimit          1500     // 用于修改apache编程参数

MaxClients          1000      //并发连接数

MaxRequestsPerChild   0      //指一个进程里可以起多少个线程,对worker更好,0为不限制

</IfModule>

如果你的网站pv值百万,可以这样设置:

ServerLimit          2500     // 用于修改apache编程参数

MaxClients          2000      //并发连接数





 

你可能感兴趣的:(vps中数据高并发下的Apache优化配置)