These days, everyone expects sites to be super fast. For instance, Google’s LightHouse audit tool recommends that a page should load within 1.2 seconds.
Yes, 1.2 seconds sounds steep, but what if your competitors heed that advice? They are likely to get better SEO ranks, and customer visits.
For any competitive online business, that’s just too big a risk to ignore.
Which is why, here at Bobcares, a big part of our Server Support Services is about keeping web and database servers blazing fast.
Today we’ll take a look at the top ways in which our Engineers optimize Apache servers.
What causes slow servers?
Web servers can slow down in 2 ways – 1. Temporary sluggishness caused by issues such as abusive processes or traffic spikes. 2. Overall slowness due to improper resource management or usage.
Based on that, there are two ways in which our server admins speed up Apache web server:
1. 24/7 performance monitoring & emergency fix
Our experts monitor customer servers 24/7. When we notice an anomaly such as a slow site speed, we immediately login to the server, kill abusive processes, and setup resource limits to prevent another such issue.
2. Periodic performance audit & Apache tuning
We periodically audit Apache performance to find out performance bottlenecks early and resolve them before it can affect customers.
Now, let’s look into this in a bit more detail.
[ You don’t have to lose your sleep to keep your web server fast and stable. Let us help you. Our experts will monitor & maintain your server infrastructure, and keep it blazing fast. ]
How to speed up Apache web server?
Many server owners buy additional RAM or upgrade their CPU to deal with Apache performance issues.
But that’s only covering up the problem, not resolving it fully – not to mention the insanely high cost of frequent hardware upgrades.
By performance tuning Apache to match your site traffic, you can achieve over 50% speed boost, while saving on hardware costs.
So, what’s involved in Apache performance tuning?
5 step process to speed up Apache
To speed up Apache, it can be tweaked at two stages –
- During compile-time, which includes the settings used during web server install.
- At run-time, which are the parameters that have effect while running the web server.
1. Compile-time options to speed up Apache
Many often server owners install Apache using automated tools such as RPM or yum. This install has a flaw that it would be a full install, a minimal install or an install based on a predefined configuration.
While predefined or minimal installs may not give you all your required features, going for a full option install may load up the webserver files and slow it down. At Bobcares, we compile web servers for server owners based on their specific business requirement.
While going for a custom web server compilation, these points help us build a fast and efficient web server.
a. Load only the required modules
In an Apache webserver, functionalities are covered by including modules relevant for each function. These modules can be of two types – Static and Dynamic (shared).
To list the modules supported by your Apache webserver, use the command ‘apachectl -M’. While static modules are compiled into the httpd binary, dynamic modules are loaded only during run-time.
Having more static modules in the httpd binary can make it faster, but requires recompiling Apache everytime a change is needed. As a result, Dynamic modules or DSOs are now preferred more, as they can be compiled separately and loaded during run-time.
But having more dynamic or shared modules can slow down your Apache web server by about 50%, and can affect the website speed. So, caution has to be exercised while choosing the modules needed for your Apache web server.
To improve the server speed and performance, we run Apache with only the minimal required dynamic modules, as it reduces the memory footprint.
[ Periodic web server tuning can save your business from going downhill. Click here to know how our experts can keep your servers fast & secure. ]
b. Choose appropriate MPM
In Apache webserver, there are MPMs (Multi-Processing Modules) that handle the webserver connections that come to the server. MPM handles tasks such as binding to network ports on the machine, accepting connections and creating child processes.
MPMs are of two types – Prefork and Worker. In Prefork MPM, each httpd process handles one connection each. It is more fault-tolerant and secure compared to Worker, but takes up more memory and resources.
Using Worker MPM, Apache runs as a multi-threaded web server, with one thread handling each connection. This makes it suitable to handle more traffic faster and with less resource usage.
By default, most Apache software comes with the Prefork module. To speed up Apache in high-traffic servers, we switch to Worker MPM in our servers. You can identify your web server MPM using the command:
In Apache 2.4, there is support for an experimental MPM – Event MPM – that can handle multiple tasks with one thread. Hence it is even faster than the Worker MPM in handling high traffic sites with minimum memory.
We analyse the traffic projections and resource availability of each web server, and then make the decision regarding whether to choose between Worker and Prefork MPMs. We then recompile Apache with the best suited MPM.
2. Speed up Apache with run-time tweaks
With increase in customer base and website traffic over time, the performance of the Apache webserver may be affected. The compile-time settings may not be sufficient for the smooth functioning of Apache.
To enable a high performance web server through out, we optimise the run-time settings of Apache server, audit the performance regularly and then tweak the configuration settings. The most important parameters we optimise to speed up Apache are:
a. DNS lookup
Apache can try to find out the hostname of every IP that connects to it. This add delay in processing request and also lead to wastage of resources. To prevent that, we disable the ‘HostnameLookups‘ option.
When using ‘Allow from’ or ‘Deny from’ directives, we use IP address instead of a domain name or a hostname. Otherwise a double DNS lookup is performed, which further slows down the webserver.
b. AllowOverride
If ‘AllowOverride‘ is set, then Apache will attempt to open ‘.htaccess’ file in each directory that it visits. These additional file system lookups add to the latency of webserver.
So, we ideally turn it off in the server. If ‘.htaccess’ over-riding is required for a particular directory, we enable it for that directory alone.
c. FollowSymLinks and SymLinksIfOwnerMatch
Symlinks or symbolic links are file shortcuts. The apache directive ‘FollowSymLinks‘ instructs the webserver to check for symlinks and follow them. If this is ‘Off’, apache would have to issue additional checks, which would slow it down.
If ‘SymLinksIfOwnerMatch‘ directive is set, then the server will follow symbolic links only if the target file or directory is owned by the same user as the link. This check will also affect speed of apache.
For maximum performance, it is ideal to enable ‘FollowSymLinks’ and disable ‘SymLinksIfOwnerMatch’. But this can lead to security issues too, so we make the final decision after weighing both the speed and security requirements.
Get an expert to speed up your web servers!
d. Content Negotiation
Content negotiation allows client to choose the data format from the webserver resources they are requesting. We recommend to avoid content negotiation for fast response.
If at all content negotiation is required for the site, we further reduce the latency by using ‘type-map‘ files instead of ‘Options MultiViews‘ directive, as the latter cause Apache to scan the directory for files, which adds to its latency.
e. MaxClients
The ‘MaxClients‘ sets the limit on the number of simultaneous requests that can be supported by Apache webserver. If its value is too low, the connections will be put on queue and won’t be processed.
But too high a value can overload the memory and affect the speed of Apache responses. So we set an ideal value that is calculated based on the available RAM and the process size.
f. MinSpareServers, MaxSpareServers and StartServers
MaxSpareServers and MinSpareServers determine the number of child processes to be kept idle, waiting to handle apache requests. These values are important because creating child processes requires effort.
If the MinSpareServers is too low and a bunch of requests come in, then Apache will have to create more child processes to serve the requests. This will make it difficult to serve the client requests immediately.
MaxSpareServers shouldn’t be set too high, as it can cause resource problems since the idle child processes consume resources. We set these two values within optimal limits to balance the resource usage and performance.
StartServers directive sets the number of child server processes created on startup. If there are a lot of requests and Apache is restarted frequently, we set this to a relatively high value.
[ Use your time to build your business. Leave your servers to experts. Click here to know how we can help you. ]
g. MaxRequestsPerChild
The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child process will handle. With its default setting, the child process will never expire.
But this can lead to memory leakage and poor performance. Setting the value too low can cause overhead creating new processes. So we set a value in the range of a few thousands to speed up Apache.
h. KeepAlive and KeepAliveTimeout
‘KeepAlive‘ is used to keep a single connection alive to transfer all the files to load a page. This saves the time in establishing a new connection for each file and helps to speed up Apache.
‘KeepAliveTimeout’ determines how long to wait for the next request. If set too high, child processes may end up wasting resources waiting for an idle client. We set this to 2-5 seconds in low-traffic and 10 seconds in high-traffic webservers.
i. Timeout
The ‘TimeOut‘ setting determines how long Apache will wait for a visitor to send a request. In busy servers, we set it up to 120 seconds, but it is best to keep this value as low as possible to prevent resource wastage.
Note – Determining the values for Apache configuration settings is subjective to the web-traffic volume and the server resources. The values discussed here are not absolute and can vary with the production server features.
3. HTTP Compression & Caching
HTTP compression is a technique we apply to speed up Apache web servers and improve the bandwidth utilisation. The server applies gzip or deflate encoding method to the response before it is sent to the client.
Client then decompresses this payload. Payload is compressed only if the browser requests compression, otherwise uncompressed content is served. HTTP Compression is enabled in Apache using ‘mod_deflate’ module.
In caching, a copy of the data is stored at the client or a proxy server so that it need not be retrieved directly from the server. Caching frequently accessed files helps us save bandwidth, decrease server load and speed up Apache processing.
The modules mod_expires and mod_headers are configured to handle cache control through HTTP headers sent from the server. With the help of cache-control directives, we control the caching rules to speed up Apache.
Another feature we make use of, is the server side caching, in which the frequently accessed contents are stored in memory so that it can be served fast. We configure the module mod_cache to enable server side caching.
There are many other caching software such as memcached and Varnish, which we configure alongside these modules in the Apache web server to speed it up further.
Get experienced admins to keep your servers blazing fast!
4. Separate server for static and dynamic content
Apache processes that handle dynamic content takes about 3-20 MB of RAM, whereas one that serves static content requires only 1MB memory. A process that handles dynamic content can later serve static content.
This can lead to wastage of memory, which slows down high-traffic webservers. For efficient memory usage, we use separate webservers to handle static and dynamic website contents.
For instance, we use a minimal Apache webserver as the front-end server to serve static contents. Requests for dynamic contents are forwarded to the custom Apache webserver which is compiled with all the required modules.
This request forwarding is accomplished using modules such as mod_proxy and mod_rewrite. The client would not notice the difference, but feels that the requests are handled by a single webserver.
Using the two webservers, we are thus able to speed up Apache by handling static contents faster without much memory usage, thereby allocating more memory to handle resource-intensive dynamic contents.
[ You don’t have to lose your sleep to keep your web server fast and stable. Let us help you. Our experts will monitor & maintain your server infrastructure, and keep it blazing fast. ]
5. Tweak MySQL and PHP settings
Web servers rarely function alone. In most cases, there would be a database server such as MySQL and scripting language support such as PHP to accompany the Apache webserver.
We’ve realised why It is equally important to optimise the database server to avoid bottle-necks in it, which can slow down web server. We also improve the performance of PHP pages using an accelerator or caching mechanism such as Zend OPcache.
MySQL is further tweaked with options such as table fragmentation and fixing the configuration settings – max connections, buffer size, query cache size, pool size and so on.
Conclusion
Configuring Apache for maximum performance is tricky, there are no hard and fast rules or ‘one-size fits all’ values. Understanding the web server requirements is vital before experimenting with the settings.
Today we’ve discussed the top 5 ways by which our Dedicated Support Engineers keep our customer servers blazing fast. If you have a question about these steps, or need to consult an expert, click here – we’ll be happy to talk to you.
Hi
How to Fine-Tuning Apache server for only Worpress? I have a VPS server which has limited recources. I want to keep it faster. Which modules to switch off and keep running. I use Plesk Panel.
https://i.imgur.com/MqVZg7M.png
Karakaplan,
Feel free to contact our server experts at https://bobcares.com/contact-us/ . They would audit your server and fine tune it for the fastest performance.
Hi,
Which option would be better if I am using Nginx Proxy ?
Our Expert Engineers can help you to optimize your Nginx Proxy performance. We’ll be happy to talk to you on chat (click on the icon at right-bottom).
So great and informative post