1.概述多处理模块(MPM)
模块名称 | 模块说明 |
---|---|
core | 始终可用的Apache HTTP服务器核心特性 |
mpm_common | 由多个多处理模块(MPM)实现的指令集合 |
event | worker MPM的一种变体,其目标是仅为活动处理的连接使用线程,对于Linux,建议使用2.6内核,还必须确保您的的版本glibc已编译为支持EPoll |
mpm_netware | 多处理模块实现了专为Novell NetWare优化的线程web服务器 |
mpmt_os2 | 混合多进程,多线程MPM为OS/2 |
prefork | 实现一个非线程的、预分叉的web服务器 |
mpm_winnt | 多处理模块为Windows NT优化 |
worker | 多处理模块实现了一个混合的多线程多进程web服务器 |
2.配置httpd的event事件处理模块
参考官方event事件处理模块的文档:请点击这里
#查看配置httpd事件处理模块的目录
vi /etc/httpd/conf/httpd.conf
......
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
Include conf.modules.d/*.conf
......
#配置event事件处理模块
vi /etc/httpd/conf.modules.d/00-mpm.conf
# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#
LoadModule mpm_event_module modules/mod_mpm_event.so
<IfModule event.c>
StartServers 8
ServerLimit 20000
AsyncRequestWorkerFactor 20000
MaxRequestWorkers 20000
</IfModule>
#检查httpd配置是否有误
httpd -t
#重启httpd服务
systemctl restart httpd
参数名称 | 参数说明 |
---|---|
StartServers | 默认启动httpd进程数,默认8个进程 |
ServerLimit | 设置httpd服务器最大的进程数 |
AsyncRequestWorkerFactor | 限制每个进程的并发连接,默认数值为2 |
MaxRequestWorkers | 最大并发进程数 |
可以通过两种方式计算并发连接的绝对最大数量:
max_connections(最大连接数)= (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers ))* ServerLimit
max_connections (最大连接数)= (AsyncRequestWorkerFactor + 1 )* MaxRequestWorkers
3.在另一台主机上进行压力测试
ab -n 100000 -c 1020 http://172.25.0.110/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.0.110 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests
Server Software: Apache/2.4.6
Server Hostname: 172.25.0.110
Server Port: 80
Document Path: /
Document Length: 4247 bytes
Concurrency Level: 1020
Time taken for tests: 37.888 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 454500000 bytes
HTML transferred: 424700000 bytes
Requests per second: 2639.38 [#/sec] (mean)
Time per request: 386.455 [ms] (mean)
Time per request: 0.379 [ms] (mean, across all concurrent requests)
Transfer rate: 11714.81 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 128 541.9 21 15064
Processing: 1 131 1111.4 53 37758
Waiting: 1 120 1111.3 43 37758
Total: 1 259 1234.8 86 37810
Percentage of the requests served within a certain time (ms)
50% 86
66% 117
75% 149
80% 180
90% 400
95% 1069
98% 1262
99% 3071
100% 37810 (longest request)