Deliberate Restarts Only
When solving a technical problem, I rarely restart a process or my computer. But when I was less experienced, I did this often. What changed?
I learned something important that I'd like to share today. First, you should try to resist restarting processes, and second, when you feel like you must, be deliberate.
Restarting is a tempting idea. Often, it fixes the issue! But that success comes at a cost.
First, it takes time. How long does it take to restart a server? A couple of seconds. What about multiple processes? Another couple of seconds. What about restarting your computer? A minute or two. There is a cost.
Worse, that cost is zero-sum: you can't do anything else because you're finding, stopping, and starting processes, or your computer is offline. Any other problem-solving activity is halted. In a scenario like pair programming where multiple ideas might be on the table, this can be disruptive.
When it does work, what do you learn? It was a guess that inexplicably solved the problem. What's the lesson? What are you going to do next time? What happens in other environments, where restarting may not be an option?
Sometimes though, restarting feels necessary. There are ways to do it that are better than others. I try to:
- Articulate a reason
- Wait a little while
- Restart the least number of processes
- Increase the volume for next time
First, articulate a reason, out loud, why you're restarting. Here's an example: "We changed a file in the lib directory, and this server doesn't auto-load that directory." Or: "We wrote a couple dozen files and hot-reloading seems to be crashing." It doesn't have to be a perfect reason.
And, be receptive to pushback: "You don't have to restart; since V3 this platform auto-loads the schema." Or, receptive to some scientific methodology: "How could we know if lib autoloads without restarting?" I welcome and offer this kind of pushback frequently while pair programming: "We have hot-reloading on this app, as we've seen pairing this morning, so we must not be seeing this change for another reason."
Next, wait. I shoot for about ten seconds before restarting. Give the system a chance to recover, print something, or fail.
Next, restart the least number of processes necessary. If you think the server is an issue, restart just the server. Resist the urge to restart all the processes or your computer. Save yourself the time and pain of nuking everything.
Lastly, anticipate next time and increase the volume of the processes you're restarting. Increase the log levels, make failures fail louder, install profilers, etc. Ask yourself: "How could I have proven that restarting this process would help, before restarting it?”