This is a public service announcement, and it’s a little long, but if your PC is getting all sluggish on you it might help. If it’s not, come back tomorrow.
One of our developers just called me. He says he “deleted a bunch of stuff”, because his “computer was working slow”. And now his sound card doesn’t work and he wants my help.
I asked him, in my professional capacity and all seriousness: what the hell? He didn’t have much of an answer to that, it turns out.
I run into this sort of thing all the time, at the home user level, and it’s frustrating; it’s a myth, but a myth that’s been propagated by brittle software, flaky operating systems and idiot tech-support monkeys for a long time. It’s got zero basis in fact, but so many computer problems have walked and quacked just like this particular duck that I suppose it’s forgivable. From a developer, though, it’s pretty sad.
In fairness he’s a web developer, which is a lot like being a real developer except you don’t have to understand how computers work. But this applies to everyone; do not start down this road, audience. I know that every now and then your computer starts to bog down for what looks like no reason at all, and I’m here to help. This is what’s happening, and how to fix it.
I’m going to gloss over a lot of details here, but it should give you a decent sense of what’s going on. Unpertinent? I wanted to use impertinent, but that word is apparently taken.
There’s two things going on here, and the first one’s commonly called “thrashing”.
In broad terms, a computer consists of a CPU, RAM, a hard disk, and a bunch of input and output (“I/O”) widgets that move information around to and from the various bits of the computer, including the network port, screen, keyboard and so forth. The whole thing is managed by an operating system, an OS, that it’s safe to think of as a separate widget that controls all these things. Note that:
- CPUs are screamingly fast these days.
- RAM is pretty fast, but not all that fast in comparative terms, and
- Reading and writing to hard disks is pretty pokey.
Your CPU works on data, and it wants to get at that data fast. All that data is on the disk when your computer starts up, and disks are slow, so generally the OS copies programs and data off the disk and into RAM whenever they’re required, where they can be read and manipulated much faster.
If this thing you’re working on needs even more memory than there is immediately available, your OS will start swapping stuff you haven’t used in the last few fractions of a second back to the hard drive, to make room in RAM for more of whatever you’re actually working on right at the moment.
This is called “swapping”, and it actually works great until you get to the point where you’ve got a bunch of different processes competing for lots of CPU attention and lots more RAM than you have.
The problem is that each of these swapping-in-and-out transactions takes a little bit of time for the pokiest part of your system to work through. Your computer swaps some unused stuff out of RAM and back on to the hard drive so that another application can have that space, but in the time
it takes to do that, some other application (or two, or five, or more)have decided that they want more space too, so the computer swaps out some more stuff to disk for them. Pretty soon your computer is spending way more time swapping stuff on and off the disk than it is doing the stuff you actually want it to be doing, like putting the Globe & Mail in front of your eyes or ripping that DVD.
To the user, it will seem like your hard drive is going crazy, hence “thrashing”, but windows stop redrawing themselves correctly and your mouse pointer gets all choppy and sluggish. We’ll get to the remedies for this in a second.
The second thing that can happen is called “blocking”, and it’s sort of the same thing as described above, except it’s (usually) about the network instead of the hard drive. A lot of programs use what’s “blocking I/O”, which basically means “I’m the one doing the inputting and outputting now, and
until I get my answers, I’m not doing another damn thing.” Again, this is an approach that works fine most of the time, but when the number of networky programs doing networky things gets a little too exciting, your machine can suddenly seem to stop paying attention to you for no obvious reason. This is particularly frustrating for Windows users, because the Task Manager won’t actually tell you that there’s anything going on – the “System Idle” process is taking up most of the CPU time,but the PC still feels like it’s been driven into a snow drift.
Now: assuming your drive isn’t actually 100% full, I promise you that none of these things have anything to do with how many files you have on your hard drive, and the situation won’t be helped by deleting anything. But note carefully, please, that if you start deleting things you don’t think you need at random, you can very quickly make the situation a lot worse and a lot harder to fix.
Back in the bad old days when people had little tiny hard drives that were more likely to get full up, deleting some big files to free up extra swap space actually did help. And it’s also true that old,
buggy web browsers went a little crazy if they miswrote their configuration files, and deleting just the right files helped there too. In modern times deleting just the right registry entries (which I
strongly suggest you never, ever try) can have a comparable effect. But none of that makes it true in the general sense, and it never was. Trying to make your PC faster by deleting files at random is roughly like trying to have a wart removed by a drive-by shooting; it’s conceivable that it
might work, true! But odds are slim and the down side is pretty severe.
On to the actual remedies, now.
If your computer is struggling with blocking I/O, then you must be doing something that involves some pretty hefty network traffic (though a moderate amount of traffic over a very slow connection will also do it, sometimes) and if you’re doing that it should really be something you’re doing on purpose. If you
don’t know what’s doing it, it’s time to give your machine a good scrubbing; that sort of thing is often an indication of malware. As for the thrashing problem, you can try to have less big programs on the go at the same time, and restart your web browser now and then (browsers and office suites are pretty serious memory hogs, and Adobe products that get greedy or occasionally lose their minds are often problematic here), but “do less” is not an ideal solution. The thing you really want to do here is buy more RAM.
That, at the moment, is what I tell everyone who tells me they have a sluggish computer, and everyone who’s buying a new one: put as much RAM into it as you can afford. It’s the single best thing you can do on a modern PC to improve its responsiveness and feel, and just generally minimize your frustration. It might look like a fair bit of money, but I promise you, compare it to the value of your time and longevity of the machine. Compared to what you’re getting back for it, it is as close to nothing as makes no difference.
Good luck, internets. If you’ve got any questions, ask away.