Home > Operation and Maintenance > Apache > How to optimize Apache server performance

How to optimize Apache server performance

(*-*)浩
Release: 2019-12-21 15:30:47
Original
3426 people have browsed it

When configuring the website, you must fully utilize the system resources, squeeze out all the potential of the system, and maximize the website speed. Apache is an intermediate bridge between user browsing and website data. But here, although we don't do much, if we take care of it carefully, some settings will have immediate results.

How to optimize Apache server performance

1. When installing Apache, you must choose the MPM correctly

If you want the best performance of Apache, So the first step is to choose the right MPM.                                                                                                                                                              (Recommended learning: Apache Server)

Apache has 3 MPMs, which are: event, prefork and worker.

Among them, event MPM is more suitable for situations where there are a large number of continuous connections. The advantage of KeepAlive is that it can respond to multiple requests in the same TCP connection: in this way, an HTML document containing a large number of images can be accelerated by 50%. Set KeepAlive to On in the Apahce configuration file httpd.conf to start KeepAlive.

prefork is a non-threaded MPM. Its characteristics are: although it is not very fast, it is very stable. It isolates each request, so if one request fails, it does not affect other requests. The most important parameter when using prefork is MaxClients.

The MaxClients value should be large enough so that it can perform well during peak access times; but at the same time it should not be too large, causing the memory required by Apache to exceed the size of physical memory.

Worker is a newly developed MPM in the Apache2 version, which is much faster than prefork. Moreover, due to the use of multi-threads for access processing, it can handle a relatively large number of requests, and the system resource usage is smaller than that of a process-based server. Workers are the main usage of Apache 2.

Worker has two important configuration parameters: ThreadsPerChild and MaxClients. ThreadsPerChild is used to control the number of threads allowed to be created for each child process, and MaxClients is used to control the total number of threads allowed to be created.

So, how to choose these 3 MPMs?

If you need better scalability, you can choose worker or event (because they are threaded MPM); if you need better stability and compatibility (such as adapting to some old software) , you can choose prefork. "From prefork to worker: Modifying ubuntu apache working mode"

If you still can't evaluate your needs and still don't know which MPM you should choose, then it is recommended to use worker.

2. Apache configuration optimization

In Ubuntu, the main configuration file of Apache is /etc/apache2/apache.conf. The following configuration is for this file.

(1) Turn off DNS query

HostnameLookups has been set to off by default, be sure to keep this setting. If you need to count client DNS, you can use third-party software to do so.

(2) Optimize MaxClients

When Apache2 starts, it will create some processes (the number set by StartServer in the configuration file) and maintain a maximum number of MaxClients ;Every connection request exceeding this number will be queued.

The above is the detailed content of How to optimize Apache server performance. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template