Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 09 · From Scratch · Distributed Scheduler · with code: Go · about 27 min to read

Play it as a journeyTutor comes with a plan

Scheduler 03: Heap and Timing Wheel

Heap and Timing Wheel
Heap and Timing Wheel · Open board

Follows Scheduler 02: Durable Job Store, and hands off to Scheduler 04: Leader Election.

Before you start. This series builds a small job scheduler: a program you hand a piece of work and a time, and it runs that work when the time comes, again and again if you ask it to. Our scheduler already survives a restart: every job’s next run time lives in a table on disk, not only in memory. Right now, finding out which jobs are due means walking that whole table, one job at a time, every single second. This lesson replaces that walk.

Lesson 64 of 117 in From Scratch

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • Checking a million jobs, once a second
  • 1987: two engineers at DEC write down the fix
  • The desk that keeps the next visitor on top
  • A wall of pigeonholes instead of a stack
  • What the pigeonhole wall forgets
  • Which desk our scheduler builds
  • The heap’s numbers
  • The wheel’s numbers
  • The hierarchy that gives the wheel range
  • Counted: a million jobs through both
  • The crossover, and the one condition the board doesn’t say
  • What this build leaves out

Terms it explains: heap, O(1), O(log n), timing wheel, tick, cascaded, amortized.

Review From Scratch