The TL;DR: install the WP REST Cache plugin, then install wp-oembed to reduce the impact from federated servers like those running Mastodon and ActivityPub.
Clients using a social network can preload a linked page to display a preview of the site. In a centralized network, the preview is loaded and cached by a centralized hub then distributed to clients. This generates one request to the linked server (possibly more than one if the hub is geographically distributed, but still not a large number).
In a federated network, there are thousands of servers/instances. These servers don’t share a centralized cache, so each one of them that needs a preview will make a request to the link target. Because the post is rapidly shared between servers, the result is a sudden spike in requests for a preview. This load is sufficient to disrupt a shared hosting account, or even a small VPS. Even after bumping the number of available database connections, my little VPS is running out and throwing errors instead of previews. Not good.
There is a great plugin that helps with this, WP REST Cache, and I highly recommend installing it. But it stores cached pages in the database. This the request still has to load WP, and connect to the database before sending the cached file. That’s not helping with the database connection bottleneck.
To solve this problem, I wrote wp-oembed. This is a basic file cache that doesn’t need a database connection. Unlike WP REST Cache, it’s deliberately designed to be quick and unsophisticated. Through a simple rewrite rule the site’s .htaccess file, embed requests are directed to oembed.php. This code checks for an unexpired cached copy in the file system. If present, the file is returned. If not, the file is requested from WP, then cached. Setup is pretty straightforward and explained in the repository’s readme file (which echoes some of the above).
In a couple of tests, it has performed quite well. I expect the real test will be watching how my server responds to me sharing this post on Mastodon!
Recent Comments