Web server architecture with Apache

Source: Internet
Author: User
Tags server memory

Web server architecture with Apache

Web application system generally by the Web server processing the client's HTTP request, the Web server is responsible for processing static pages, dynamic page forwarding to the application server, the application server and then the data access request to the database server processing,

Client-->web Server--app server--database server

The effect of MPM on Apache performance
Worker MPM: Uses multiple child processes, each of which has multiple threads, and each thread processes a request. This mpm is usually a good choice for high-traffic servers because it requires less memory and is more scalable than prefork MPM
Prefork MPM: Multiple child processes are used, but each child process does not contain multiple threads, each process processes only one connection, and on many systems it is as fast as the worker MPM, but requires more memory. The design of this wireless path is superior to the worker mpm in some cases, as it can be applied to third-party modules that do not have thread safety, is easy to debug on platforms that do not support thread debugging, and has a higher stability than the worker mpm.

Adjust Max clients
Memory is one of the important factors that affect Web servers, and with Prefork MPM, because each process takes up a certain amount of memory, you need to be careful to adjust the max clients parameter so that you don't run out of server memory while providing enough connectivity to the client, Max Client refers to the maximum number of server processes that Apache can enable.
If this is the case, you can infer that you may need to increase the server memory to the maxclients number of Apache.
The increase in the number of online sites, access is slow, initially considered to be insufficient server resources, but repeated testing, once connected, and constantly click on the same page of the connection, can be opened quickly, this phenomenon shows that the maximum number of Apache connections is full, new visitors can only queue to wait for idle connections, and if once connected, There is no need to reopen the connection during the lifetime of the keepalive, so the workaround is to increase the maximum number of Apache connections.
VI httpd-mpm.conf
# prefork MPM
# Startservers:number of server processes to start
# minspareservers:minimum number of server processes which is kept spare
# maxspareservers:maximum number of server processes which is kept spare
# Serverlimit:maximum value for maxclients for the lifetime of the server
# maxclients:maximum number of server processes allowed to start
# maxrequestsperchild:maximum number of requests a server process serves
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
Serverlimit 256
MaxClients 256
Maxrequestsperchild 4000
</IfModule>

# prefork MPM
# Startservers:number of server processes to start
# minspareservers:minimum number of server processes which is kept spare
# maxspareservers:maximum number of server processes which is kept spare
# maxrequestworkers:maximum number of server processes allowed to start
# maxconnectionsperchild:maximum number of connections a server process serves
# before terminating
<ifmodule mpm_prefork_module>
Startservers 5 #启动Apache时就启动的服务器进程
Minspareservers 5 #最少保留的备用服务器进程
Maxspareservers #最大保留的备用服务器进程
Maxrequestworkers 250
Maxconnectionsperchild 0 #一个服务器进程可处理的请求数量
</IfModule>

# worker MPM
# startservers:initial number of server processes to start
# maxclients:maximum number of simultaneous client connections
# minsparethreads:minimum number of worker threads which is kept spare
# maxsparethreads:maximum number of worker threads which is kept spare
# threadsperchild:constant number of worker threads in each server process
# maxrequestsperchild:maximum number of requests a server process serves
<ifmodule worker.c>
Serverlimit 32
Threadlimit #必须放到最前面
Startservers 4
MaxClients 300
Minsparethreads 25
Maxsparethreads 75
Threadsperchild 25
Maxrequestsperchild 0
</IfModule>
Maxspareservers: Refers to the Apache most reserved standby server process, if your system memory is not very sufficient, or run with other services, the Maxspareservrs set smaller can be other services to empty some memory

Mod_cache
Mod_cache: In order to support the cache, it needs to be enabled at compile time, and the default caching is disabled. Mod_cache There are 3 mod_mem_cache,mom_disk_cache,mod_file_cache in total,
To be able to compile the cache, you need to set it at compile time
--enable-cache--enable-disk-cache--enable-mem-cache--enable-file-cache
After installation, compile httpd.conf, add
<ifmodule mod_cache.c>
Cachedefaultexpire 3600
Cachemaxexpire 86400
Cachelastmodfiedfactor 0.1

<ifmodule mod_disk_cache.c>
Cacheroot/usr/local/apache2/cache #创建读写权限
Cachemaxfilesize 10000000
Cacheminfilesize 1
cacheenable Disk/#
Cachedirlevels 5
Cachedirlength 3
</IfModule>
</IfModule>
<ifmodule mod_mem_cache.c>
Cacheenable Mem/
Mcachesize 4096 #缓存数据最多能够使用的内存
Mcahemaxobjectcount #内存中最多能够缓存对象的个数
Mcaheminobjectsize 1 #单个缓存对象的最小值
Mcahemaxobjectsize 2048 #单个缓存对象的最大值
</IfModule>

This article from the "SAR Monitoring Command" blog, declined reprint!

Web server architecture with Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.