8 Timer Implementation Patterns for Systems and Network Software

https://hackernoon.imgix.net/images/code-review-best-practices-tkyvwfp2pgz96biyr8y0fwjy.png

Times in the System

If you've ever worked on network protocol stacks, kernel/driver code, or any system-level application, you've run into the same deceptively simple problem: how do I make something happen after a certain amount of time has passed — reliably, and at scale?

It sounds trivial until you're managing thousands of concurrent timers — per-neighbor BGP hold timers, per-tunnel keepalives, retransmission timeouts — and your naive implementation starts burning CPU cycles just walking a list. Over the years, systems engineers have converged on a handful of proven patterns for this. Here's a rundown of the most common approaches, from the hardware level up to modern event-driven frameworks.

1. Hardware Timers/Interrupt-Driven Timers

At the lowest level, you have actual timer peripherals on the chip. These generate a hardware interrupt the moment they expire, and an Interrupt Service Routine (ISR) picks up the signal and fires off the corresponding timeout...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more