All posts

When a system is slow, don’t buy a more powerful server

2 min read

“Shouldn’t we buy a more powerful server?”

I get this question every time something in a system drags and people end up waiting on it several times a day. It sounds logical — if it’s slow, the machine probably isn’t up to it.

The answer is almost always no, and precisely because a more powerful machine doesn’t speed everything up equally. Some things it speeds up noticeably. But anything waiting on the disk, on the network, or on one single step that can’t be split up, it barely speeds up at all. You pay considerably more and the screen takes almost as long to open — and with a rented server, you pay that again every month.

Measure first, fix after

Before I start changing anything, I want to know where the time is really being spent. Not by guessing, not by what “looks slow” — I measure it. That screen was about a customer’s credit limit, and it took 38 seconds to open. The measurement showed that almost all of that time was spent in one single spot: a query that asked the database for data in a way that forced it to go through far more than it needed to.

I rewrote the query so that it asked more cleverly — put together differently, with the same result. The 38 seconds became half a second. The server stayed the same, and nothing was bought.

You can make it faster the wrong way, too

And here comes the second half of the story. Rewriting a query is a handy thing, as long as it does exactly the same as before, only faster. But it can also be rewritten so that it starts calculating something else. Not something completely different — someone would notice that on day one. But slightly different. And “slightly different” looks, at first glance, just like “the same” — until a few months later two numbers meet that don’t match, and nobody knows why.

That’s why, with a change like this, it isn’t enough to try a few examples I happen to have on hand. I picked those examples myself, so I’m bound to pick the ones where it works. I need to know that the new and the old version, by their very nature, give the same answer to anything. It’s the difference between “we tried it and it worked” and “it can’t turn out any other way.”

I describe this on a bigger scale in the article on how to rewrite a system so that nobody notices.

What the client gets out of it

No invoice for a new server that the client would pay for month after month just so that screen opens a few percent faster. Instead, one specific thing, found by measuring and fixed exactly where it is. And the certainty that after the fix the system still calculates the same as before — just a good deal faster.

More posts