If a related posts box compares each article with the whole blog on every view, store its results for a day, match by tags or category instead, and pick related posts by hand for key articles.

A warning from the host

A small tour company has blogged about its trips for four years: a post for every tour, every new route and every guide's favourite viewpoint. Lately the blog has turned sluggish, with pages taking several seconds to appear.

Then the host writes. The account is using more than its share of the shared server's processor and database, and if that continues, the site may be limited or suspended.

Nothing obvious has changed. The theme is the same, traffic is ordinary for summer, and the newest posts look like the old ones. The cause sits in a small box under every article: related posts.

What the box does on every view

Many related posts add-ons work out the list fresh each time a post is shown.

They take the current post's title and words, ask the database to compare them with every other post, score the matches and show the top five.

Nothing is remembered from one view to the next, so the database repeats the same work for the next visitor a moment later.

Why it grows with the blog

With forty posts, the comparison takes a moment. With nine hundred, each view asks the database to weigh nine hundred posts, and the work grows with every post published.

The slowdown is gradual, so it goes unnoticed at first. Pages get a little slower each month until the host's monitoring catches it before anyone in the office does.

Robots add load that visitors never see. A search engine revisiting old posts overnight runs the comparison on each one, at an hour when no person is reading.

How the host sees it

On shared hosting, many accounts share one server's processor, memory and database. Hosts set limits on each account's share so that one busy site does not slow the rest.

A related posts query that reads much of the database on every view looks, from the host's side, like a site doing far too much work for the visits it gets.

The warning is about that work, not about the number of visitors.

Some hosts also slow an account down automatically once it passes its limit, which can explain why the pages felt sluggish before any warning arrived.

Keeping the results for a day

Related posts do not need to be fresh to the second. The best matches for an article written last year will not change before tomorrow.

Many add-ons can store each post's list once it is worked out and reuse it for a day or a week. The comparison then runs once per post per day instead of once per view.

A page cache, which saves each finished page and serves that copy to the next visitor, goes further: most views then skip the database entirely.

A worked example

A wedding cake baker in Summerland has posted every cake she has made for five years, each with photographs, the flavours, the venue and a word about the couple.

The blog is her portfolio, and couples browse it for ideas. Under each post, a related cakes box listed five others, comparing that post's text with every other post on every view.

The host's warning arrived in the middle of wedding season. Her developer found the related posts query near the top of the host's slow query report, then timed a page with the box and without it. The difference was plain.

The box now picks related cakes by shared tags, such as the flavour, the style and the season, which the database can answer from its index without reading every post. The results are stored for a day.

For the dozen posts couples visit most, she chooses the related cakes herself, so a lemon cake for a vineyard wedding leads to others like it.

Looking up a tag takes the database a moment; comparing the whole blog on every view never could.

A lighter way to choose

Matching by category or shared tags, newest first, asks the database a much simpler question. It can answer from an index, the way a book's index finds a page without reading the book.

The matches are less clever than a full text comparison, but for most blogs they are good enough, and readers rarely notice the difference.

Tags only help if they are used consistently. A short, agreed list of tags is worth more than dozens invented on the spot.

Ask whoever built the site to confirm that the tag match really uses the index, because a carelessly written tag query can be slow as well.

Choosing by hand

For the posts that matter most, a person choosing three related articles beats any formula. A writer knows which post answers the next question a reader is likely to have.

A field on the editing screen for chosen related posts, with the automatic list as a fallback, gives both: care where it counts and no extra work elsewhere.

Hand-picked links also suit seasonal posts, where the best companion is often an article written a year earlier for the same season.

The counter-case

A young blog with a few dozen posts and modest traffic will not trouble any server with a related posts box, however the box works.

A site on its own server with room to spare may also carry the load comfortably for years.

The work still grows with every post, though, and the time to choose a lighter method is before the host's warning, not after it.

Lightening the box under each post

  1. Time a post with the related posts box on and off.
  2. Ask your host for the slow query report.
  3. Store each post's list for a day or more.
  4. Add a page cache for visitors who are not logged in.
  5. Match by tags or category instead of the full text.
  6. Pick related posts by hand for your most visited articles.
  7. Tidy the tag list so the matches make sense.

Step three is the quickest relief. Storing the lists turns a comparison on every view into one per post per day, often with a single setting.

Another kind of hidden work on every page view, a theme asking for files that no longer exist, is tracked down in missing files that every page still asks for.


Frequently asked questions

Why would a related posts box slow a blog down?

Many work out the list fresh on every view, comparing the post with every other post in the database. On a large blog that is heavy work, repeated for every visitor.

Why did the host warn us when traffic is normal?

The warning is about the work each visit causes, not the number of visits. A heavy query on every page view uses more than an account's share of a shared server.

Does it get worse over time?

Yes. Each new post adds one more to compare against, so the work behind every view grows with the blog, gradually enough to go unnoticed.

What does storing the results do?

It keeps each post's list for a day or a week, so the comparison runs once per post per day instead of once for every visitor.

Are tag-based related posts good enough?

For most blogs, yes, if tags are used consistently. The database can answer a tag match from its index without reading every post.

When is choosing related posts by hand worth it?

For the articles visitors reach most often. A writer knows which posts answer the next question, and the automatic list can cover everything else.

West Coast Media Solutions Inc. provides web design, web development, hosting, digital marketing, and business consulting to organisations across Canada, drawing on more than twenty-five years in the field.

Host warning you about server load?

Point us to your blog, and we will find which part of each page view is doing the heavy work.

Start a Conversation