I thought I'd provide an update on the work I've been doing behind the scenes over the last couple of weeks to address server load and improve the performance of the Puritan Board.
The Puritan Board shares a fairly powerful dedicated server with a number of other websites that I host. One of the challenges in administering a server like this is that performance problems are not always attributable to a single website or service. There are also a number of inefficiencies that can accumulate over the years as applications are upgraded, plugins come and go, and the nature of Internet traffic changes.
The sheer volume of automated traffic on the Internet has also become a significant problem. Between search engine crawlers, AI scrapers, malicious bots, and other automated processes, there is an enormous amount of traffic hitting websites that has nothing to do with actual human beings visiting them.
I've spent considerable time examining virtually every major component of the server, and I thought some of the more technically inclined members might appreciate an explanation of what I've been doing.
Cloudflare and Bot Traffic
I've been experimenting with a number of Cloudflare protections to reduce the amount of automated traffic that actually reaches the server. I've examined access logs, identified problematic IP addresses and networks, and experimented with various challenge and rate-limiting rules.
Some of these measures worked better than others. I experimented with restricting direct web traffic to the server so that requests had to come through Cloudflare, but ultimately reversed that change because of complications with other services and websites.
I also experimented with more aggressive challenges on certain areas of the Puritan Board, only to discover that some of these interfered with legitimate XenForo functionality, including the login process. I subsequently modified or removed rules that were causing problems for members.
I currently have Cloudflare's "I'm Under Attack" mode enabled. I recognize that this introduces some inconvenience for visitors, and I don't intend to leave it enabled indefinitely. My plan is to disable it in a few days and assess how the server performs with the other optimizations in place.
Elasticsearch
The Puritan Board uses Elasticsearch to provide its search functionality. One of the things I discovered was that Elasticsearch had been configured with a Java heap allocation of nearly 14.5 GB on a server with approximately 28 GB of RAM.
That was consuming a disproportionate amount of the server's available resources relative to the size of the Puritan Board's search index.
I reduced that allocation to 6 GB, which provides substantial capacity for our search requirements while making significantly more memory available for other services.
PHP Optimization
One of the more significant discoveries was how inadequately PHP's OPcache had been configured for the number and complexity of websites on the server.
For those unfamiliar with OPcache, PHP applications consist of scripts that have to be compiled into instructions that PHP can execute. OPcache allows those compiled instructions to be retained in shared memory rather than requiring PHP to repeatedly compile the same scripts.
I substantially increased the memory available to OPcache, increased the number of scripts it could accommodate, and expanded the memory available for shared strings.
The server is now caching more than 93,000 PHP scripts, and the cache hit rate is approximately 99.89%. Nearly 90.4 million cache hits have been recorded in just a few hours of operation following the latest configuration changes.
I also reconfigured PHP-FPM, which manages the PHP processes that serve the various websites. This included optimizing the way processes are created, how long they remain available, and how frequently they are recycled.
I subsequently examined the actual private memory consumption of these processes to ensure that the changes were not simply exchanging one performance problem for another. The results have been very encouraging.
Redis and Persistent Object Caching
Another fairly substantial undertaking was implementing persistent object caching across 36 WordPress installations that reside on the same server as the Puritan Board.
WordPress can be rather inefficient in the number of database queries and other operations it performs to generate pages. Persistent object caching allows the results of many of these operations to be retained in memory and reused.
I established 31 dedicated Redis instances, segregated by hosting account, so that the various websites could benefit from persistent object caching without interfering with one another.
The results have been impressive. One of the busier hosting accounts alone has already recorded more than 7.6 million Redis cache hits, with a hit rate of nearly 97%.
All of these additional Redis services combined are currently consuming less than 700 MB of actual resident memory.
WordPress Scheduled Tasks
Another source of inefficiency was the manner in which WordPress handles scheduled tasks. By default, WordPress relies on website traffic to initiate checks for scheduled background operations.
Multiply that across dozens of websites, particularly when those websites are being visited by large numbers of automated bots, and it creates a considerable amount of unnecessary activity.
I replaced this mechanism with server-managed scheduled tasks and staggered their execution so that multiple websites would not all attempt to perform their background maintenance at the same time.
Video Metadata Caching
One of the more surprising discoveries involved websites that display embedded Vimeo videos using certain WordPress page-building tools.
Vimeo informed me that the server had been generating more than a million requests per day for video metadata. In some cases, information about the same video was being requested more than 100 times per minute.
I developed a WordPress plugin to cache Vimeo and YouTube video metadata locally, eliminating the need for the websites to repeatedly contact those services for information they had already obtained.
This not only reduces unnecessary server activity but also addresses problems with Vimeo throttling requests from the server.
Database Optimization
I also spent considerable time optimizing MariaDB, the database engine used by the Puritan Board and the other websites.
Among other things, I:
The recent InnoDB cache hit rate is now approximately 99.95%. The rate at which MariaDB has to retrieve pages that are not already in its buffer pool has also declined dramatically.
I've temporarily configured MariaDB to log queries taking longer than a quarter of a second so that I can identify and investigate any remaining inefficiencies.
Where Things Stand Now
The cumulative results of these optimizations have been extraordinary.
A couple of weeks ago, I was frequently observing periods during which the server had very little available memory, was using nearly all of its allocated swap space, and was struggling under significant bursts of activity.
As of this afternoon:
There is something of a cumulative effect to these optimizations. Reducing unnecessary PHP operations reduces database activity. Improving database caching reduces disk activity. Reducing unnecessary scheduled tasks frees up CPU resources. Caching objects and video metadata eliminates operations that never needed to be repeated in the first place.
I'm not yet declaring victory over the bot traffic problem. The real test will come when I disable Cloudflare's "I'm Under Attack" mode and observe how the server behaves under more normal traffic conditions. Some of the improvement in server load is undoubtedly attributable to the Cloudflare protections currently in place, and I want to distinguish that from the improvements attributable to the server itself.
Nevertheless, the underlying efficiency of the server is demonstrably better than it was two weeks ago, and it now has considerably more capacity to deal with periods of heavy traffic.
I appreciate everyone's patience with the occasional inconveniences as I've worked through these issues. There is quite a bit involved in keeping a site like the Puritan Board running, particularly in an Internet environment where an increasing proportion of the traffic consists of machines talking to other machines.
Hopefully, the end result will be a faster, more responsive, and more reliable Puritan Board for those of us who are actually human.
The Puritan Board shares a fairly powerful dedicated server with a number of other websites that I host. One of the challenges in administering a server like this is that performance problems are not always attributable to a single website or service. There are also a number of inefficiencies that can accumulate over the years as applications are upgraded, plugins come and go, and the nature of Internet traffic changes.
The sheer volume of automated traffic on the Internet has also become a significant problem. Between search engine crawlers, AI scrapers, malicious bots, and other automated processes, there is an enormous amount of traffic hitting websites that has nothing to do with actual human beings visiting them.
I've spent considerable time examining virtually every major component of the server, and I thought some of the more technically inclined members might appreciate an explanation of what I've been doing.
Cloudflare and Bot Traffic
I've been experimenting with a number of Cloudflare protections to reduce the amount of automated traffic that actually reaches the server. I've examined access logs, identified problematic IP addresses and networks, and experimented with various challenge and rate-limiting rules.
Some of these measures worked better than others. I experimented with restricting direct web traffic to the server so that requests had to come through Cloudflare, but ultimately reversed that change because of complications with other services and websites.
I also experimented with more aggressive challenges on certain areas of the Puritan Board, only to discover that some of these interfered with legitimate XenForo functionality, including the login process. I subsequently modified or removed rules that were causing problems for members.
I currently have Cloudflare's "I'm Under Attack" mode enabled. I recognize that this introduces some inconvenience for visitors, and I don't intend to leave it enabled indefinitely. My plan is to disable it in a few days and assess how the server performs with the other optimizations in place.
Elasticsearch
The Puritan Board uses Elasticsearch to provide its search functionality. One of the things I discovered was that Elasticsearch had been configured with a Java heap allocation of nearly 14.5 GB on a server with approximately 28 GB of RAM.
That was consuming a disproportionate amount of the server's available resources relative to the size of the Puritan Board's search index.
I reduced that allocation to 6 GB, which provides substantial capacity for our search requirements while making significantly more memory available for other services.
PHP Optimization
One of the more significant discoveries was how inadequately PHP's OPcache had been configured for the number and complexity of websites on the server.
For those unfamiliar with OPcache, PHP applications consist of scripts that have to be compiled into instructions that PHP can execute. OPcache allows those compiled instructions to be retained in shared memory rather than requiring PHP to repeatedly compile the same scripts.
I substantially increased the memory available to OPcache, increased the number of scripts it could accommodate, and expanded the memory available for shared strings.
The server is now caching more than 93,000 PHP scripts, and the cache hit rate is approximately 99.89%. Nearly 90.4 million cache hits have been recorded in just a few hours of operation following the latest configuration changes.
I also reconfigured PHP-FPM, which manages the PHP processes that serve the various websites. This included optimizing the way processes are created, how long they remain available, and how frequently they are recycled.
I subsequently examined the actual private memory consumption of these processes to ensure that the changes were not simply exchanging one performance problem for another. The results have been very encouraging.
Redis and Persistent Object Caching
Another fairly substantial undertaking was implementing persistent object caching across 36 WordPress installations that reside on the same server as the Puritan Board.
WordPress can be rather inefficient in the number of database queries and other operations it performs to generate pages. Persistent object caching allows the results of many of these operations to be retained in memory and reused.
I established 31 dedicated Redis instances, segregated by hosting account, so that the various websites could benefit from persistent object caching without interfering with one another.
The results have been impressive. One of the busier hosting accounts alone has already recorded more than 7.6 million Redis cache hits, with a hit rate of nearly 97%.
All of these additional Redis services combined are currently consuming less than 700 MB of actual resident memory.
WordPress Scheduled Tasks
Another source of inefficiency was the manner in which WordPress handles scheduled tasks. By default, WordPress relies on website traffic to initiate checks for scheduled background operations.
Multiply that across dozens of websites, particularly when those websites are being visited by large numbers of automated bots, and it creates a considerable amount of unnecessary activity.
I replaced this mechanism with server-managed scheduled tasks and staggered their execution so that multiple websites would not all attempt to perform their background maintenance at the same time.
Video Metadata Caching
One of the more surprising discoveries involved websites that display embedded Vimeo videos using certain WordPress page-building tools.
Vimeo informed me that the server had been generating more than a million requests per day for video metadata. In some cases, information about the same video was being requested more than 100 times per minute.
I developed a WordPress plugin to cache Vimeo and YouTube video metadata locally, eliminating the need for the websites to repeatedly contact those services for information they had already obtained.
This not only reduces unnecessary server activity but also addresses problems with Vimeo throttling requests from the server.
Database Optimization
I also spent considerable time optimizing MariaDB, the database engine used by the Puritan Board and the other websites.
Among other things, I:
- Increased the InnoDB buffer pool from approximately 110 MB to 4 GB.
- Increased the capacity of the database's table caches.
- Converted 124 WordPress database tables from the older MyISAM storage engine to InnoDB.
- Removed numerous obsolete database tables left behind by plugins that had been uninstalled years ago.
- Optimized heavily fragmented database tables, recovering more than a gigabyte of wasted disk space.
- Cleaned up obsolete WordPress options that were being unnecessarily loaded into memory.
- Removed remnants of outdated security, statistics, and e-commerce plugins.
- Enabled slow query logging to identify any remaining database performance bottlenecks.
The recent InnoDB cache hit rate is now approximately 99.95%. The rate at which MariaDB has to retrieve pages that are not already in its buffer pool has also declined dramatically.
I've temporarily configured MariaDB to log queries taking longer than a quarter of a second so that I can identify and investigate any remaining inefficiencies.
Where Things Stand Now
The cumulative results of these optimizations have been extraordinary.
A couple of weeks ago, I was frequently observing periods during which the server had very little available memory, was using nearly all of its allocated swap space, and was struggling under significant bursts of activity.
As of this afternoon:
- The server has approximately 10 GB of available RAM.
- There is no significant active swapping in the latest monitoring samples.
- CPU utilization is quite low during normal periods of activity.
- The five-minute server load average has fallen to approximately 1.5 on a server with 12 logical processors.
- PHP's compiled script cache has a hit rate of nearly 99.9%.
- The database's recent InnoDB cache hit rate is approximately 99.95%.
- All 36 WordPress installations are benefiting from persistent object caching.
- PHP has processed more than 86,000 requests since this morning without recording a slow request in its current monitoring statistics.
There is something of a cumulative effect to these optimizations. Reducing unnecessary PHP operations reduces database activity. Improving database caching reduces disk activity. Reducing unnecessary scheduled tasks frees up CPU resources. Caching objects and video metadata eliminates operations that never needed to be repeated in the first place.
I'm not yet declaring victory over the bot traffic problem. The real test will come when I disable Cloudflare's "I'm Under Attack" mode and observe how the server behaves under more normal traffic conditions. Some of the improvement in server load is undoubtedly attributable to the Cloudflare protections currently in place, and I want to distinguish that from the improvements attributable to the server itself.
Nevertheless, the underlying efficiency of the server is demonstrably better than it was two weeks ago, and it now has considerably more capacity to deal with periods of heavy traffic.
I appreciate everyone's patience with the occasional inconveniences as I've worked through these issues. There is quite a bit involved in keeping a site like the Puritan Board running, particularly in an Internet environment where an increasing proportion of the traffic consists of machines talking to other machines.
Hopefully, the end result will be a faster, more responsive, and more reliable Puritan Board for those of us who are actually human.