Roughly how long does a CPU Context Switch (swapping threads/processes) take?
- A approximately 1 to 5 microseconds ($\mu$s)
- B approximately 1 millisecond (ms)
- C approximately 10 nanoseconds (ns)
- D approximately 100 ms
A 'Context Switch' occurs when the OS stops one thread and starts another on the same CPU core. This involves saving CPU registers, flushing the Translation Lookaside Buffer (TLB), and loading the state of the new task, which typically takes about 1-5 microseconds. While this sounds fast, it is 'eternity' compared to a single CPU instruction (0.5 nanoseconds). If a system is forced to switch contexts too frequently (hundreds of thousands of times per second), the CPU spends more time 'managing' the work than actually *doing* the work—a state known as thrashing. This is why highly concurrent systems often use 'thread pools' or 'async task workers' to minimize these expensive swaps.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What is the maximum allowed downtime per year for a system targeting '99.9%' (Three Nines) availability?
- What is the typical size of a standard ASCII character (e.g., 'A')?
- What is the typical Round Trip Time (RTT) for a single network packet traveling between New York and London (Transatlantic)?
- Network bandwidth is usually denoted in **bits** per second (Gbps), while storage is in **Bytes** (GB). What is the conversion ratio?
- Storing a password using a secure algorithm like bcrypt (cost 10) or Argon2 typically consumes how much storage per user?
- How much power does a typical fully-loaded rack-mount server consume?