I thought I'd share some lessons learned over the past couple of weeks in dealing with extraordinarily high server loads on a fairly established XenForo forum. Hopefully, some of this will be useful to other administrators who are experiencing similar problems.
I've been administering forums for more than 20 years and have a reasonably good understanding of server administration, but the nature of the automated traffic we're dealing with today presents some challenges that are quite different from what we were accustomed to several years ago.
For context, my environment consists of:
I created some monitoring scripts that collect detailed performance statistics every 30 minutes. Among other things, I'm monitoring:
One of the benefits of doing this is that I can distinguish between a CPU bottleneck, memory pressure, database inefficiency, disk contention, and excessive incoming traffic. A load average by itself doesn't tell you nearly enough.
Some useful Linux commands to become familiar with if you haven't already:
vmstat 1 10
pidstat -u 1 10
iostat -xz 1 10
free -h
sar -u
sar -q
sar -W
I would particularly encourage people to look at available memory rather than simply free memory, and active swap-in/swap-out activity rather than merely the amount of swap occupied.
PHP OPcache
My OPcache configuration was woefully inadequate for the number of PHP applications hosted on the server. I progressively increased its capacity and monitored the results.
I'm now using 4 GB of OPcache memory, 256 MB for interned strings, and a significantly larger accelerated file limit. The cache currently accommodates approximately 90,000 scripts with a hit rate of approximately 99.96%, ample free capacity, and no restarts due to memory or hash exhaustion.
Obviously, you don't need these allocations for a single XenForo installation. The point is to actually look at your OPcache statistics rather than assume the defaults are adequate.
MariaDB
My InnoDB buffer pool was also considerably undersized. I increased it to 4 GB and made some adjustments to the table caches.
The difference in physical page reads has been remarkable. My recent InnoDB buffer pool hit rates have consistently exceeded 99.9%, and in some of my latest measurements have exceeded 99.99%.
I also temporarily enabled slow-query logging with a threshold of 250 milliseconds to identify expensive recurring queries.
One XenForo-specific discovery concerned the activity log used for trending content. I had a substantial amount of historical activity data that wasn't really necessary for the way I wanted trending content to work. Reducing the activity retention period and adjusting the trending half-life allowed me to eliminate a considerable amount of accumulated data through XenForo's normal cleanup mechanism.
Elasticsearch
Elasticsearch had been allocated considerably more JVM heap than it actually needed. After reviewing the index size, heap utilization, garbage collection statistics, and search performance, I was able to reduce the heap allocation to 6 GB without any observed degradation in search performance.
PHP-FPM
I reviewed the configuration of the PHP-FPM pools across the server, including process limits, idle timeouts, and process recycling.
Be careful about simply increasing the maximum number of PHP workers when your server is struggling. If CPU capacity is already the limiting factor, allowing more concurrent PHP execution may make the situation worse.
WordPress
Since I host a number of WordPress sites, I also implemented persistent Redis object caching, cleaned up some bloated databases and obsolete plugin data, and moved WordPress scheduled tasks to staggered system cron jobs.
These changes helped improve the efficiency of the overall hosting environment, but I won't go into much detail here since this is a XenForo community.
I use Cloudflare Pro and had already implemented a number of security rules, rate limits, and bot protections. Nevertheless, I was experiencing periods of extremely high server load.
I had resorted to using Cloudflare's "I'm Under Attack" mode, which was effective at reducing the load but was also more intrusive than I wanted for normal forum operation.
I started analyzing the Apache access logs to determine precisely what requests were reaching the server.
One thing I would encourage other XenForo administrators to do is to analyze not just the most frequently requested URLs, but also:
Within a few minutes, the PHP-FPM reported request rate increased from approximately 4 requests per second to more than 80. My one-minute load average increased from about 4 to 28.
What was interesting was that the database, memory, and storage resources were all holding up extremely well. I still had more than 9 GB of available RAM, virtually no active swapping, and almost no disk I/O wait.
CPU utilization was the problem, and the vast majority of the processes consuming CPU were associated with my XenForo PHP-FPM pool.
I analyzed approximately five minutes of access logs during this period. Here are some of the more interesting statistics:
This is strongly suggestive of large-scale, distributed automated content browsing, potentially using rotating proxy services. I can't establish the precise identity or intent of the clients, but the traffic pattern was extraordinary.
This also explains why conventional per-IP rate limiting and blocking individual IP addresses weren't accomplishing much. If the vast majority of IP addresses make only one request, how are you going to establish a reasonable rate limit that doesn't also interfere with legitimate users?
Approximately 56% of the requests in my sample generated HTTP 301 responses, with the vast majority associated with thread URLs and individual post navigation.
Requests involving paths such as:
/threads/thread-title.12345/post-67890
/goto/post
can require XenForo to perform application processing to determine the appropriate destination. If the client follows the redirect, it may then generate another request requiring additional application processing.
When you multiply this by thousands of distributed clients, you can end up expending substantial CPU resources on navigation and redirect processing before the actual discussion content is even served.
Incidentally, during my investigation I also discovered that some of my old vBulletin redirect scripts were no longer compatible with the current version of XenForo and were generating HTTP 500 errors. I installed the current XenForo redirect add-on and restored the functionality of those historical links.
Further log analysis confirmed that the legacy vBulletin redirects were not a significant contributor to the current traffic problem, but it was a useful discovery nonetheless.
I discovered an inconsistency in my DNS configuration that allowed some traffic to bypass Cloudflare entirely.
Because I'm using Apache's mod_remoteip to recover the original visitor IP address, this wasn't immediately apparent from my ordinary access logs.
Recent versions of cPanel maintain an additional Apache traffic log at:
/var/log/cpanel-server-traffic/web/traffic-apache.log
On my server, this log contains both the actual connecting IP address and the visitor IP address recovered through Cloudflare.
Comparing the actual connection address against Cloudflare's published IP ranges allowed me to determine what proportion of traffic was actually passing through Cloudflare.
I would encourage administrators to verify:
Obviously, cleaning up DNS records doesn't prevent someone who already knows your origin IP from connecting directly. Origin access restrictions are a separate security measure worth investigating, especially if your server hosts multiple domains and you cannot simply restrict ports 80 and 443 to Cloudflare globally.
I already had Super Bot Fight Mode enabled, including JavaScript Detections and protection against definitely automated traffic. These protections were useful but weren't sufficient to deal with the volume of distributed browsing I was experiencing.
What ultimately appears to have made the biggest difference was applying Managed Challenges more selectively to the types of browser navigation responsible for most of the workload.
The general approach was to create a custom WAF rule that:
The browser headers are not a reliable means of identifying malicious clients by themselves, and legitimate visitors may still receive challenges. Nevertheless, the approach appears to be filtering a substantial portion of the unnecessary traffic in my environment.
I'm deliberately not posting my complete production security rules, but the approach should give others some ideas about what to investigate.
A word of caution regarding XenForo AJAX requests
Be very careful about applying Managed Challenges to XenForo's login, keep-alive, service worker, and other AJAX endpoints.
I previously experimented with challenging login-related requests and discovered that it could interfere with normal login functionality. The problem is that XenForo expects a particular response from the server, and Cloudflare may instead return an HTML challenge page.
I've found it preferable to challenge appropriate top-level browser navigation rather than indiscriminately challenge all requests associated with particular URL prefixes.
I would also caution against simply blocking /index.php without understanding the query-string routes being requested.
Here is a comparison of the measurements:
These are snapshots taken under different traffic conditions rather than a controlled laboratory benchmark, but the difference is substantial.
I've also tested normal browsing, login and logout, individual post navigation, What's New, quoting and replying, chat, and mobile browsing.
Everything I've tested is working properly.
The forum is currently operating without Under Attack mode, although visitors may encounter occasional Managed Challenges as they navigate the site.
I'm going to continue monitoring the server to determine whether the improvements are sustained.
You can spend a considerable amount of money upgrading your server and still find yourself struggling if thousands of distributed clients are continually demanding application resources.
Conversely, you can implement aggressive security rules and make life miserable for your legitimate forum members if you don't understand how XenForo uses its various endpoints.
The objective is to find a reasonable balance between the two.
I'd be interested in hearing from other XenForo administrators who are experiencing similarly distributed traffic, particularly those who have found effective ways of dealing with large-scale automated content browsing using Cloudflare Pro without having to keep Under Attack mode enabled indefinitely.
I've been administering forums for more than 20 years and have a reasonably good understanding of server administration, but the nature of the automated traffic we're dealing with today presents some challenges that are quite different from what we were accustomed to several years ago.
For context, my environment consists of:
- A VPS with 12 logical CPUs and approximately 29 GB of RAM.
- AlmaLinux 8 with WHM/cPanel.
- Apache with PHP 8.3 and PHP-FPM.
- MariaDB 11.4.
- Elasticsearch for XenForo Enhanced Search.
- Cloudflare Pro for my XenForo domain.
- Approximately three dozen WordPress installations on the same server.
1. Establish what is actually causing your server load
I think one of the mistakes we can make as forum administrators is to assume that high server loads necessarily mean we need more server resources. Another is to assume that XenForo itself is inefficient when the underlying issue may be the sheer volume of unnecessary requests we're asking it to process.I created some monitoring scripts that collect detailed performance statistics every 30 minutes. Among other things, I'm monitoring:
- CPU utilization and load averages.
- Available memory and active swapping.
- Disk I/O latency.
- PHP-FPM worker utilization.
- MariaDB performance and cache efficiency.
- Redis memory utilization and evictions.
- Elasticsearch heap utilization.
- Apache access logs, including request rates, response codes, most frequently requested URLs, source IPs, and user agents.
One of the benefits of doing this is that I can distinguish between a CPU bottleneck, memory pressure, database inefficiency, disk contention, and excessive incoming traffic. A load average by itself doesn't tell you nearly enough.
Some useful Linux commands to become familiar with if you haven't already:
vmstat 1 10
pidstat -u 1 10
iostat -xz 1 10
free -h
sar -u
sar -q
sar -W
I would particularly encourage people to look at available memory rather than simply free memory, and active swap-in/swap-out activity rather than merely the amount of swap occupied.
2. Review your underlying server configuration
Before I got very far into analyzing the traffic, I discovered several opportunities to improve the efficiency of the server itself.PHP OPcache
My OPcache configuration was woefully inadequate for the number of PHP applications hosted on the server. I progressively increased its capacity and monitored the results.
I'm now using 4 GB of OPcache memory, 256 MB for interned strings, and a significantly larger accelerated file limit. The cache currently accommodates approximately 90,000 scripts with a hit rate of approximately 99.96%, ample free capacity, and no restarts due to memory or hash exhaustion.
Obviously, you don't need these allocations for a single XenForo installation. The point is to actually look at your OPcache statistics rather than assume the defaults are adequate.
MariaDB
My InnoDB buffer pool was also considerably undersized. I increased it to 4 GB and made some adjustments to the table caches.
The difference in physical page reads has been remarkable. My recent InnoDB buffer pool hit rates have consistently exceeded 99.9%, and in some of my latest measurements have exceeded 99.99%.
I also temporarily enabled slow-query logging with a threshold of 250 milliseconds to identify expensive recurring queries.
One XenForo-specific discovery concerned the activity log used for trending content. I had a substantial amount of historical activity data that wasn't really necessary for the way I wanted trending content to work. Reducing the activity retention period and adjusting the trending half-life allowed me to eliminate a considerable amount of accumulated data through XenForo's normal cleanup mechanism.
Elasticsearch
Elasticsearch had been allocated considerably more JVM heap than it actually needed. After reviewing the index size, heap utilization, garbage collection statistics, and search performance, I was able to reduce the heap allocation to 6 GB without any observed degradation in search performance.
PHP-FPM
I reviewed the configuration of the PHP-FPM pools across the server, including process limits, idle timeouts, and process recycling.
Be careful about simply increasing the maximum number of PHP workers when your server is struggling. If CPU capacity is already the limiting factor, allowing more concurrent PHP execution may make the situation worse.
WordPress
Since I host a number of WordPress sites, I also implemented persistent Redis object caching, cleaned up some bloated databases and obsolete plugin data, and moved WordPress scheduled tasks to staggered system cron jobs.
These changes helped improve the efficiency of the overall hosting environment, but I won't go into much detail here since this is a XenForo community.
3. Look at your actual origin traffic
This was probably the most important part of the exercise.I use Cloudflare Pro and had already implemented a number of security rules, rate limits, and bot protections. Nevertheless, I was experiencing periods of extremely high server load.
I had resorted to using Cloudflare's "I'm Under Attack" mode, which was effective at reducing the load but was also more intrusive than I wanted for normal forum operation.
I started analyzing the Apache access logs to determine precisely what requests were reaching the server.
One thing I would encourage other XenForo administrators to do is to analyze not just the most frequently requested URLs, but also:
- URL families such as /threads/, /goto/, /posts/, and /whats-new/.
- Query strings associated with /index.php.
- HTTP response codes.
- The distribution of requests across individual IP addresses and networks.
- User agents associated with particular request types.
4. The nature of distributed automated browsing
I conducted a controlled experiment in which I disabled Under Attack mode while monitoring the server.Within a few minutes, the PHP-FPM reported request rate increased from approximately 4 requests per second to more than 80. My one-minute load average increased from about 4 to 28.
What was interesting was that the database, memory, and storage resources were all holding up extremely well. I still had more than 9 GB of available RAM, virtually no active swapping, and almost no disk I/O wait.
CPU utilization was the problem, and the vast majority of the processes consuming CPU were associated with my XenForo PHP-FPM pool.
I analyzed approximately five minutes of access logs during this period. Here are some of the more interesting statistics:
- Approximately 20,000 HTTPS requests reached Apache.
- Approximately 17,400 requests involved navigation to threads and individual posts.
- Those 17,400 requests came from approximately 15,800 distinct IP addresses.
- More than 91% of those IP addresses made exactly one request in the thread and post navigation sample.
- The most active individual IP address made only eight requests in that sample.
- More than 11,000 requests generated HTTP 301 redirects.
This is strongly suggestive of large-scale, distributed automated content browsing, potentially using rotating proxy services. I can't establish the precise identity or intent of the clients, but the traffic pattern was extraordinary.
This also explains why conventional per-IP rate limiting and blocking individual IP addresses weren't accomplishing much. If the vast majority of IP addresses make only one request, how are you going to establish a reasonable rate limit that doesn't also interfere with legitimate users?
5. Pay attention to XenForo redirects
Another interesting discovery was the sheer volume of redirects.Approximately 56% of the requests in my sample generated HTTP 301 responses, with the vast majority associated with thread URLs and individual post navigation.
Requests involving paths such as:
/threads/thread-title.12345/post-67890
/goto/post
can require XenForo to perform application processing to determine the appropriate destination. If the client follows the redirect, it may then generate another request requiring additional application processing.
When you multiply this by thousands of distributed clients, you can end up expending substantial CPU resources on navigation and redirect processing before the actual discussion content is even served.
Incidentally, during my investigation I also discovered that some of my old vBulletin redirect scripts were no longer compatible with the current version of XenForo and were generating HTTP 500 errors. I installed the current XenForo redirect add-on and restored the functionality of those historical links.
Further log analysis confirmed that the legacy vBulletin redirects were not a significant contributor to the current traffic problem, but it was a useful discovery nonetheless.
6. Verify that traffic is actually going through Cloudflare
Don't assume that because your site is configured in Cloudflare, all requests reaching your server have passed through Cloudflare.I discovered an inconsistency in my DNS configuration that allowed some traffic to bypass Cloudflare entirely.
Because I'm using Apache's mod_remoteip to recover the original visitor IP address, this wasn't immediately apparent from my ordinary access logs.
Recent versions of cPanel maintain an additional Apache traffic log at:
/var/log/cpanel-server-traffic/web/traffic-apache.log
On my server, this log contains both the actual connecting IP address and the visitor IP address recovered through Cloudflare.
Comparing the actual connection address against Cloudflare's published IP ranges allowed me to determine what proportion of traffic was actually passing through Cloudflare.
I would encourage administrators to verify:
- Both the WWW and non-WWW DNS records are proxied.
- There are no unexpected DNS-only website records.
- Apache is configured to trust forwarded visitor IP headers only from Cloudflare's published networks.
- Your origin server isn't unnecessarily accepting direct connections that bypass your Cloudflare security rules.
Obviously, cleaning up DNS records doesn't prevent someone who already knows your origin IP from connecting directly. Origin access restrictions are a separate security measure worth investigating, especially if your server hosts multiple domains and you cannot simply restrict ports 80 and 443 to Cloudflare globally.
7. Develop more targeted Cloudflare security rules
As I mentioned, I'm using Cloudflare Pro, not Business or Enterprise.I already had Super Bot Fight Mode enabled, including JavaScript Detections and protection against definitely automated traffic. These protections were useful but weren't sufficient to deal with the volume of distributed browsing I was experiencing.
What ultimately appears to have made the biggest difference was applying Managed Challenges more selectively to the types of browser navigation responsible for most of the workload.
The general approach was to create a custom WAF rule that:
- Targets GET requests involving forum content navigation.
- Excludes Cloudflare-verified bots.
- Uses browser fetch headers to distinguish top-level document navigation from AJAX requests.
- Applies Managed Challenges to relevant thread, post, and recent-content navigation paths.
The browser headers are not a reliable means of identifying malicious clients by themselves, and legitimate visitors may still receive challenges. Nevertheless, the approach appears to be filtering a substantial portion of the unnecessary traffic in my environment.
I'm deliberately not posting my complete production security rules, but the approach should give others some ideas about what to investigate.
A word of caution regarding XenForo AJAX requests
Be very careful about applying Managed Challenges to XenForo's login, keep-alive, service worker, and other AJAX endpoints.
I previously experimented with challenging login-related requests and discovered that it could interfere with normal login functionality. The problem is that XenForo expects a particular response from the server, and Cloudflare may instead return an HTML challenge page.
I've found it preferable to challenge appropriate top-level browser navigation rather than indiscriminately challenge all requests associated with particular URL prefixes.
I would also caution against simply blocking /index.php without understanding the query-string routes being requested.
8. The results so far
After refining my Cloudflare rules, I conducted another controlled experiment with Under Attack mode disabled.Here is a comparison of the measurements:
| Metric | Under Attack enabled | First test without Under Attack | Targeted protection with Under Attack disabled |
|---|---|---|---|
| PHP-FPM reported requests/sec | 3.8 | 80.3 | 12.0 |
| Active PHP workers | 1 | 18 | 4 |
| CPU idle | 79% | 8.5% | 78.3% |
| Available RAM | 9.7 GB | 9.4 GB | 9.4 GB |
| Swap occupied | 710 MB | 695 MB | 688 MB |
I've also tested normal browsing, login and logout, individual post navigation, What's New, quoting and replying, chat, and mobile browsing.
Everything I've tested is working properly.
The forum is currently operating without Under Attack mode, although visitors may encounter occasional Managed Challenges as they navigate the site.
I'm going to continue monitoring the server to determine whether the improvements are sustained.
9. Some recommendations for other XenForo administrators
If you're experiencing similar server load problems, I would recommend approaching the problem in roughly this order:- Establish historical server performance monitoring rather than relying exclusively on instantaneous load averages.
- Verify that your PHP OPcache, database buffers, PHP-FPM pools, and Elasticsearch configuration are appropriate for your actual workload.
- Use slow-query logging to identify expensive application queries.
- Analyze your web server access logs to determine which URL families are generating the most work.
- Examine the distribution of requests across IP addresses before assuming that rate limiting will solve the problem.
- Verify that traffic isn't bypassing Cloudflare.
- Review your existing Cloudflare rules for overly broad challenges, unnecessary exceptions, and gaps in protection.
- Consider more targeted challenges for the types of navigation generating excessive workload.
- Test normal XenForo functionality after every significant security configuration change.
- Change one major aspect of your configuration at a time where possible, and measure the results.
You can spend a considerable amount of money upgrading your server and still find yourself struggling if thousands of distributed clients are continually demanding application resources.
Conversely, you can implement aggressive security rules and make life miserable for your legitimate forum members if you don't understand how XenForo uses its various endpoints.
The objective is to find a reasonable balance between the two.
I'd be interested in hearing from other XenForo administrators who are experiencing similarly distributed traffic, particularly those who have found effective ways of dealing with large-scale automated content browsing using Cloudflare Pro without having to keep Under Attack mode enabled indefinitely.