Optimize Apache server performance
Network administration - Optimizing Apache server performance can make a difference on your website and the impression it creates, especially on dynamic sites . In this article we will cover the basics of configuration and installation, two areas that you can control to optimize the performance of the Apache server.
Evaluating and improving performance
Apache is designed to be as fast as possible. However, as sites become more complex and the bandwidth needs of different connection types increase, then getting the best performance in an Apache installation and website becomes an important issue.
Improving performance does not mean making changes to achieve negligible results. Spending hours or even days adjusting a server for a few percent is a waste of time. So the first step is to determine how fast your server is and its overall performance level in order to improve performance and evaluate your changes.
This is not the first time we have introduced Apache testing. As noted above, determining which components in web applications are causing problems - especially distinguishing whether Apache or the application environment you are using with dynamic sites is difficult. . Identifying problems in dynamic applications goes beyond the scope of this article, but we'll show you some ways to improve Apache's overall speed and how it interacts with components. How to support a website?
Server hardware
The computer and operating system environment in which Apache is running has the greatest impact. Obviously, an old 386 computer will not be as good as a P4 or dual-processor computer, but you can make some improvements to it. To avoid changing hardware, the biggest thing you can do is make sure Apache is running on a dedicated server. In addition, the existence of other applications also significantly affects the performance of web servers.
In most situations, especially static websites, the amount of RAM is an important factor because it will affect the amount of information that Apache can remember (cache). The more information that is cached, the lower the Apache performance in handling open and reading a file on the disk. If the site is based on most static files, then consider using mod_cache ; If there is a lot of RAM, then you can consider mod_mem_cache .
Saving information to the disk before creates a significant difference if the site is based on mod_include to build up a page. With mod_mem_cache , the information stored in the heap is shared by all Apache processes.
Using a high-speed disk will be better, Redundant Array of Inexpensive Disks (RAID) is one of the options (RAID 0, 0 + 1, 5, 10, or 50) will improve speed. Access to the served files.
Note, however, that if you experience a problem on a certain route, an alternative hardware solution for software is the best option.
Finally, in terms of hardware, CPU performance can have an impact on dynamic sites with additional overhead for application execution for each page accessed. Dynamic pages often require higher CPUs.
Host environment
Regardless of the operating system, use the optimization principle below:
- Keep background apps to a minimum. If you really care about performance, you need to first consider that there are some processes that work in the background. For example, in Unix, you should turn off NFS, print services, and even sendmail if not needed. In Windows, use the System control panel to optimize the system for applications and system cache, optimize the system for performance. Just make sure that the required applications and services like MySQL are still running.
- Avoid using the system . If you start compiling applications, editing files or using the machine, then surely your web server performance will decrease. So if you have to edit components or install software, build or edit components on another computer and then copy them later.
- Need to update the system continuously . Although the idea comes from a security standpoint, software upgrades and patch updates also significantly improve input and output performance and network performance.
Apache application
Clearly Apache is also an application. So first make sure it is built correctly with modules and extensions for websites. That means, for example, you can ignore the recorded models if not needed. The main benefit of that is reducing memory load, but another good benefit is that you cannot accidentally activate the options and thus reduce server performance.
Static and dynamic
Flexibility is a major issue for most Apache administrators, but its flexibility has its price. Using dynamic modules inside Apache makes it convenient, but they also affect performance, because the code will be loaded when the module requires it. Dynamic modules also have the advantage of keeping the set requirements low.
To build a static mode, use the configuration script and specify the modules you want, but do not specify sharing (such as using enable-rewrite without using --enable-rewrite = shared , or use the --enable-so sharing option.
Modular configuration
If you're using Apache's static configuration, choose the modules you want to merge to take care of. Using static mode also costs - the more modules, the more memory is consumed. Thus, a multi-processor module can be significantly effective on the memory requirements of the machine.
Note that there are some entries that are automatically added, so you need to explicitly activate and disable the necessary modules. Also remember to include third-party modules (such as authentication, PHP or mod_perl), web service requests. Use the configuration -help to get a list of available options.
Server configuration
When your environment is set up and your Apache application is optimized, this is where you pay attention to the configuration file for more robust optimization. A good way is to start by cleaning up the file so that directives (directive) are limited to a few hundred numbers by removing comments. In addition, it becomes the removal of unnecessary components or components that do not provide legitimate benefits.
Simplify configuration file
The first step to optimization is to simplify the configuration file. While there will be no obvious improvement in performance, it will make the configuration file easier to use and so you will avoid omitting directives or components that need to be changed.
If you perform any optimization type, start with one of the default configuration files provided. Your files are usually saved in the Apache configuration directory under the name httpd.conf.orig or httpd-std.conf. Do not use the high performance-std.conf file; in the long run it is not really as useful as what you think when you start adding a large amount of additional configuration information. On the other hand, if your goal is a static, speedy web server, this is definitely the easiest way for you to do that.
If you know the instructions for configuring Apache, or are willing to study the documentation, the most efficient and fastest step you should take is to remove all comments from the configuration file, as they often reduce the reputation of the directives. . You can also remove references to MPM systems that are not currently used on the selected platform.
Disable components and systems
Now that we have a simple configuration file, start removing the configuration components for systems that are not currently in use. Specifically:
- HostnameLookups, which will often add overhead to each request by requesting DNS lookups on the client, first observe to find the name from the IP address, then look up to make sure that information is not mistaken. In most cases, you can simply disable it. If you usually deal with your log files, use post-processing to determine the information. To disable the lookup, the indicator group below HostnameLookups off .
- Symbolic links, which , when enabled, will cause Apache to check every request to determine whether a symbolic link is relevant in the request. Unless you really need these symbolic links, turn it off by using:: Options -FollowSymLinks
- Server status and info , this is a component although it is very useful when testing and testing the server, but it will create additional overhead for the web server. Disable by looking for SetHandler server-status directives , and if possible, remove the module from Apache when you configure the application during the build process.
- Wildcards and flexible options should be avoided if you can. For example, the DirectoryIndex directive, will explicitly instruct the list of configured files, always listing the most appropriate options first.
- CGI execution is required unless you have a good reason for not doing so. Put all CGI files into a directory and configure it for CGI execution. This will prevent Apache from trying to determine if the request is indeed a CGI component or a static file.
Disable logs
Writing log information is a time consuming process. Even so, Apache is always open to this feature, so it will consume a lot of server time. If saving the log information is unnecessary, you can save some processing cycles by disabling it. To do this, note the record lines in the configuration file.
If you decide to keep your logs, disable HostnameLookups (see above) and make sure to copy the log information to another machine to analyze the files.
Simplify directory level configuration
.Htaccess files are very useful files for expanding Apache server configuration parameters without having to edit the main configuration file every time you want to change something. The problem here is that using them will slow down your server.
First, the server must observe whether the .htaccess file exists or not, then it must parse and process these components before using the configuration for the directory in question. Worse, Apache must identify this information not only for the current directory but also for the parent directories and then make changes based on the content of all these files.
However, if you want to maximize performance, you should disable the use of .htaccess files. Any specific directory configuration can go into the main configuration file, where it can be parsed once by Apache when the server starts.
To disable .htaccess add AllowOverride None directive and sections .
Configure MPM
Multi-Processing Module (MPM) allows a specific platform to manage multiple connections simultaneously. MPM modules are specific to each platform. Available solutions work specifically with Unix, Windows, BeOS and NetWare. For some platforms there are often many choices. For most users, the default configuration for a particular environment works quite well, especially when obtaining the correct parameters can be a time-consuming task. By comparison, many of the techniques described can bring better performance, but when you want to get the maximum performance for your server, you still have to adjust the configuration.
Under most platforms only MPM, Unix have two options prefork and worker . The prefork MPM divides some of the same Apache processes, while the worker creates multiple threads. In general, prefork is better on systems with one or two processors, where the operating systems support better for cutting down time between processes. On systems with a higher number of CPUs, the thread model will definitely be more efficient.
In almost all cases, the MaxClients directive is most effective for increasing server performance, as it controls the maximum number of concurrent connections that the Apache server can manage.
Optimize static components
If your website uses a lot of static components, or if you separate static and dynamic components on two or more web servers, your main goal will be to improve the response time that Apache sends back the information. News requested. The easiest way to do this is to use the mod_cache module. You can use this module with the mod_disk_cache and mod_mem_cache to provide the memory and disk cache of static files.
Check the Apache documentation on the mod_cache module for more detailed information.
Optimize dynamic components
Dynamic components will definitely be the most time-consuming component for any web server. They, especially if you use CGI, will increase the response time to load and execute a simple application. More information is available for you to consult at mod_perl, PHP, and Python and Java.
The main advantage of script-based solutions is that they embed an interpreter into Apache, which helps remove the initial loading problem for dynamic scripts. Some even save the analyzed script to easily be executed if required later.
Configuration can be complicated and getting the correct system can be time consuming. Some solutions also do not work well such as the solution expected with virtual hosts, you will need to change certain scenarios to take advantage of the speed improvements that it provides.
However, the improvements here are significant, which can reduce 70% of execution time for a Perl script using mod_perl instead of CGI. Even with more work, these solutions also allow you to keep solid connections with the database or can store information between requests. This is great for e-commerce sites and also contributes to reducing the overhead of loading information between requests.
Conclude
Although Apache is a configurable and rather complex application, it is really interesting because its standard settings achieve very high levels of performance. One area where you can easily improve performance by adjusting parameters. Unfortunately, the parameters that you have little control inside Apache - such as dynamic components and CGI scripts - are the ones that have the greatest impact on performance. Checking a typical Apache server, you will find that the time for the Apache application to respond to a connection and send data back in just a few ms - but waiting for that data source can take a few seconds. .
However, this is not something we insist on optimal action is meaningless. During one line work, the number of ms will increase. More importantly, you can clean up and simplify your Apache configuration, which helps it reduce administrative overhead during implementation.
You should read it
- How to install and configure Apache on Rocky Linux
- How to enable performance optimization in Windows 10
- Critical error on Apache Struts2 allows hackers to take over the web server
- How to Install Apache Guacamole via Docker on Ubuntu 22.04
- Apache 2 supports SSL / TLS: Step by step instructions (Part II)
- Instructions for creating virtual hosts with Apache in Ubuntu
- Top 5 RAM optimization software, enhance computer performance
- Compare Nginx and Apache
- How to Install Tomcat in Ubuntu
- How to check for simple Linux server performance
- Adjust performance in SQL Server: find slow queries
- MSI presents the laptop to play 'dinosaur' GE70 Apache Pro
Maybe you are interested
How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04
How to install and configure Apache on Rocky Linux
How to Install Apache Guacamole via Docker on Ubuntu 22.04
How to install Apache Netbean on Windows 10
How to Enable Cross Origin Resource Sharing (CORS) for Sharing Resource Using Apache Servers, PHP and Jquery
How to Set up Php on Apache 2.2.3 on CentOS 5.3