Puritan Board Server Optimizations

Semper Fidelis

2 Timothy 2:24-25
Staff member
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:

  • 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.
Some of the database cleanup was quite remarkable. One security logging table on another website was consuming more than a gigabyte of disk space, almost all of which was wasted space. After optimization, that same table occupied less than 19 MB without losing its records.

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.
What is particularly satisfying about all of this is that I have not had to purchase additional hardware or increase the server's hosting costs. I've simply been able to make much more effective use of the resources that are already available.

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.
 
A few more updates on things I've discovered since my last post.

One interesting discovery last night was that some of our old vBulletin redirects were no longer working. When we migrated from vBulletin to XenForo years ago, we retained the ability to redirect links to old threads and posts to their corresponding locations in XenForo. There are links to Puritan Board discussions scattered across the Internet going back more than 20 years. Some of the legacy redirect scripts were no longer compatible with our current version of XenForo and were generating server errors. I've implemented the newer redirect mechanism and verified that old links are once again resolving to the appropriate discussions.

I've also made some additional discoveries concerning the amount of automated traffic hitting the Board. I've implemented some fairly extensive monitoring on the server that collects performance statistics every 30 minutes. What is remarkable is how much the traffic can vary over the course of a few hours. At one point this morning, the Board was receiving nearly 15 times the number of requests it was receiving yesterday evening, even with Cloudflare's heightened security measures in place.

I discovered this morning that some traffic was reaching the server without passing through Cloudflare's protections. I've corrected a configuration issue and am monitoring the results before implementing some additional protections.

There have also been some additional refinements to the way the server handles caching and background processing. Since the server hosts a number of other websites besides the Puritan Board, improvements to the efficiency of those sites also benefit the Board by freeing up resources.

The encouraging news is that, despite some extraordinary fluctuations in traffic, the server is handling the workload much better than it was before. The database is now finding more than 99.97% of requested InnoDB data pages in memory, and PHP is achieving a similar cache hit rate for compiled code. Both of these improvements substantially reduce the amount of work the server has to perform to serve a page.

I'm increasingly convinced that we have sufficient server resources to handle the legitimate traffic the Board receives. Much of the remaining work involves figuring out how to prevent the server from expending those resources on unnecessary traffic.

I'm trying to be fairly methodical about the remaining changes so I can measure their effects rather than simply changing a bunch of settings and hoping for the best. I appreciate everyone's patience as I continue working through these issues.
 
Another Server Update: Under Attack Mode Disabled

I'm pleased to report that I've been able to turn off Cloudflare's "I'm Under Attack" mode and the Board is currently performing very well.

Since my last update, I've spent considerable time analyzing the nature of the traffic hitting the Puritan Board. One of the benefits of the monitoring I've put in place is that I can now correlate the traffic reaching the server with its actual resource utilization and better understand what is causing the performance problems.

I conducted an experiment earlier this afternoon in which I disabled Under Attack mode. Within a few minutes, the amount of traffic being processed by PHP increased from about 4 requests per second to more than 80. CPU utilization increased dramatically, and I had to re-enable Under Attack mode.

What was encouraging, however, was that the other server resources held up remarkably well. We still had more than 9 GB of available memory, the database was performing extremely efficiently, and there was virtually no disk contention. This helped confirm that many of the optimizations I've made over the past several days are doing what I intended them to do.

I then spent some time analyzing the requests themselves. In less than five minutes, the server received approximately 17,400 requests for threads and individual posts from nearly 16,000 distinct IP addresses. More than 91% of those IP addresses made only a single request. This is strongly suggestive of distributed, automated browsing of the Board's content. It also explains why some of the more conventional approaches to blocking excessive traffic have had limited effectiveness.

I've since refined the security rules in Cloudflare to deal more specifically with this kind of traffic. Rather than subjecting everyone visiting the Puritan Board to heightened security checks, I'm now applying more targeted protections to the types of requests that have been generating the excessive workload.

You may still encounter an occasional Cloudflare Managed Challenge as you navigate the Board, but you should no longer be subjected to the more intrusive site-wide Under Attack mode. I've tested logging in, browsing discussions, navigating to individual posts, What's New, quoting, replying, and several other Board functions, and everything appears to be working properly.

I've also accomplished quite a bit of housekeeping since my last update:

  • Conducted a comprehensive DNS audit covering nearly 500 hostnames associated with the websites on the server.
  • Removed more than 50 obsolete DNS records accumulated over many years of hosting websites.
  • Corrected some inconsistencies in the way website traffic was being routed through Cloudflare.
  • Verified that our database performance optimizations survived a server reboot.
  • Verified that the dedicated caching services for the other websites on the server are operational and that the scheduled background processing we've been monitoring is functioning properly.
  • Continued refining the automated performance monitoring so I can better diagnose problems when they occur rather than relying on a snapshot of server activity after the fact.
Since disabling Under Attack mode for the second time this afternoon, PHP is processing about 12 requests per second rather than the 80-plus we experienced during the earlier experiment. At the most recent measurement, nearly 80% of the server's CPU capacity was idle, and the server had more than 9 GB of available memory. The database continues to achieve a cache hit rate well above 99.9%.

I'm going to leave things alone for a while and see how the server performs overnight. There are still a few things I intend to address, but I think we're finally getting to the point where the server is operating efficiently and we have a much better handle on the traffic reaching it.

Please let me know if you encounter any difficulties with normal Board functionality. In particular, I'd like to know if Cloudflare challenges are interfering with anything you're trying to do.

Thank you again for your patience over the past several days.
 
I was the same way but I finally switched a few years ago; you can get a program like Start11 to overlay and look like Windows 7. The risk is too real and all my programs were aging me out and would not be able to update.
Every time you get on the internet with a Win 7 maching you are shouting: "Please hack my computer!"
Yea!!! Finally able to log in with Win7 again. I've been having to use Win11.
 
Every time you get on the internet with a Win 7 maching you are shouting: "Please hack my computer!"
And every time you get on the internet with a factory default Win11, you are saying, please log all of my keystrokes.

As they say, "The cloud is just someone else's computer'.

In any event, thanks for your labors in keeping the Puritan Board safe and accessible. We tend to not think of the effort you expend until something does go wrong (such as AI going on a hacking spree, or a WordPress module release with a security hole in it).
 
I think he meant with the default settings that come with a fresh Win11 install, you essential let MS know everything about what you do with your computer.

I am done with Windows and Mac. I’ve been on Debian (on a 2015 Macbook Pro) for the past two months and have not looked back. I will only capitulate back to Windows to use CAD CAM software required by work. But that will be on a work computer.
 
I think he meant with the default settings that come with a fresh Win11 install, you essential let MS know everything about what you do with your computer.

I am done with Windows and Mac. I’ve been on Debian (on a 2015 Macbook Pro) for the past two months and have not looked back. I will only capitulate back to Windows to use CAD CAM software required by work. But that will be on a work computer.
I can understand wanting more say over what your computer sends to Microsoft. Windows 11 does send diagnostic information about your machine and how it’s running. Some of the more detailed reporting, including information about app usage, is optional. So I think “everything you do” overstates it, but I understand the privacy objection. And if Debian gives you a few more good years out of a 2015 MacBook Pro, that strikes me as a pretty good reason to use it. I run this Board on Linux myself. support.microsoft.com

I was just talking yesterday to a friend who investigates open-source repositories. One of the things he traces is which widely used software libraries have contributors in China. A developer’s nationality, by itself, tells me very little about whether I can trust a particular change. What I care about, working in national security, is who has the authority to put that change on my machine. Anybody can submit a patch. Who can approve it? Who can publish the update? Who independently checks what actually ships? I’d ask those same questions if the developer lived down the road from me in Virginia.

Consider what happened with XZ Utils in 2024. XZ is a compression tool, about the last place most of us would think to look if remote logins started acting strangely. Yet that’s where an engineer traced the problem after he noticed that SSH logins on his Debian system were using more CPU than they should. Two signed XZ releases contained a backdoor, and a crucial piece was present only in the release archives. You could have read the code in the public repository and still missed what was being shipped. To Debian’s credit, the affected versions were caught in its development branches before they reached Debian stable.

So if your point is that you’d prefer to keep Microsoft out of the picture on your personal machine, fair enough. Where I think the sense of security becomes illusory is in the leap from “anyone can inspect this code” to “someone I trust has inspected the software I’m about to install.” Every time I update the server that runs this Board, I’m trusting people most of us have never heard of. That’s worth remembering whichever operating system we use.
 
Another Server Optimization Update

I've spent a considerable amount of time over the last 24 hours continuing to optimize the server. As I noted in previous updates, one of the challenges is that the Puritan Board shares a server with a number of other websites that I host. What happens on those sites affects the resources available to the Board.

While much of the earlier work involved properly allocating memory and tuning the various services that run on the server, much of the recent work has involved identifying things the server simply doesn't need to be doing.

Among the things I've accomplished in the last day:

  • Continued to optimize the scheduling of background WordPress tasks so that dozens of websites aren't competing for resources unnecessarily or initiating maintenance tasks in response to visitors.
  • Optimized the way all 37 WordPress installations handle requests for images that no longer exist. Previously, a request for a missing image could cause WordPress to load PHP, query the database, and generate an entire web page to tell somebody that an image wasn't there. Apache now handles those requests directly.
  • Validated full-page caching on 34 WordPress installations. Most of these sites are now delivering cached pages from the server in about 30 milliseconds without having to invoke PHP or query the database.
  • Identified and removed a number of remnants from previously installed caching and security plugins, including well over a gigabyte of obsolete cache files.
  • Identified several anti-spam and registration plugin configurations that were preventing otherwise cacheable pages from being cached and corrected them.
  • Corrected some longstanding configuration issues on older websites, including five sites that still had HTTP references in their underlying WordPress configuration despite serving pages over HTTPS.
  • Continued to refine a plugin I developed to cache information from YouTube and Vimeo rather than repeatedly requesting the same information from those services when pages are generated.
  • Implemented additional Cloudflare protections across the websites I manage to prevent certain abusive crawlers and requests from ever reaching the server.
I've also spent quite a bit of time analyzing the traffic coming into the Puritan Board itself.

One of the interesting things about the traffic patterns we've been observing is that simply looking at the number of requests from a particular IP address doesn't tell you much anymore. Automated traffic can come from thousands of different IP addresses, and some of it looks remarkably like normal browser traffic. In addition to requesting threads, it causes the forum software to perform a number of other background operations.

In one comparison earlier today, changes I made in Cloudflare reduced the number of requests reaching the Board by about 59%, with an approximately 85% reduction in login keep-alive requests and similarly significant reductions in other background activity.

One thing I discovered, however, was that some of the security rules I had implemented were also interfering with legitimate AI crawlers. I've consolidated several of those rules and made allowances for legitimate, verified crawlers. I've also disabled a more broadly applied challenge rule that was affecting navigation around the Board.

My general philosophy is that I want the content on the Puritan Board to be accessible. We have accumulated a considerable body of theological discussion over the years, and I don't particularly mind search engines and AI services making use of that material. I do mind automated services behaving in a manner that makes the Board less accessible to its members. I would rather identify and deal with the latter than indiscriminately block automated traffic.

The encouraging thing is how much healthier the server is compared to a couple of weeks ago.

On November 18, the server was averaging nearly 74% CPU utilization, with a system load of approximately 17. It was also using nearly all of its available swap space.

In the measurements I took following today's work and the server restart, CPU utilization was averaging about 12%, system load was approximately 1.5, and nearly 15 GB of RAM was available. There was very little swap utilization and no significant active swapping.

Those aren't precisely equivalent periods of measurement, but even before today's restart there had been a significant improvement in the daily averages. The improvement is not simply a function of restarting the server.

I've also developed a number of scripts that allow me to monitor the health of the various services on the server and to better understand what is happening when the server comes under load. I'm getting much better visibility into the relationships between web traffic, PHP processes, database activity, caching, memory utilization, and the various maintenance tasks that take place overnight.

At this point, I intend to spend more time monitoring than changing things. I want to see how the server behaves over the course of a normal day, including its overnight backup operations, and determine whether the additional crawler traffic I'm now permitting has any appreciable impact on performance.

My goal isn't to have a server that sits idle because I've prevented everybody from accessing it. My goal is to have a server that can handle a considerable amount of legitimate traffic without wasting resources doing things it doesn't need to do.

I appreciate everyone's patience as I've worked through these issues. I'm considerably more satisfied with the state of the server than I was two weeks ago.
 

Windows 11 "Recall" feature plus the default Office 365 uploads to OneDrive, and there isn't much that isn't going to M$. Add in Microsoft Edge to track your browsing, and there isn't much that Microsoft doesn't have (and potential subpoenas can't reach) about your computer use.

One can negotiate for enterprise level Copilot, of course, which promises to not use your documents and emails to feed its AI.

Some of the more detailed reporting, including information about app usage, is optional.
Yes, some of it can be turned off - but initially at least, 'on' was the default and the user had to research and manually turn them off. You are more up to date than me, so maybe some of that has changed. But that was the basis of my 'factory default' comment.

Thank you again for the hours of work you have put in to keeping the Board up and running smoothly.

I am done with Windows
So YOU are the reason MS stock is down almost $100 a share from its peak. ;)
 
So if your point is that you’d prefer to keep Microsoft out of the picture on your personal machine, fair enough. Where I think the sense of security becomes illusory is in the leap from “anyone can inspect this code” to “someone I trust has inspected the software I’m about to install.” Every time I update the server that runs this Board, I’m trusting people most of us have never heard of. That’s worth remembering whichever operating system we use.
Precisely, and well said, Rich. This is also the reason why I have an affinity to Debian (stable release) over other distros.
 
Debian 12 derivative on a 2007 laptop, and I feel more secure than I ever did on a windows owned machine.

Thank you Rich for putting your tech knowledge to good use!
 
Back
Top