Several Steps and a Budget
Last timeWhen a Tool Fails
A loop with no limit is not a capability, it is an invoice. Bounding the steps, the time and the money is what makes a multi step system safe to run.
Three budgets, not one
The step limit in the second lesson is the obvious bound and on its own it is the weakest of the three.
Twenty steps might be two seconds of fast lookups or two minutes of web fetches. It might be a tenth of a penny or several pounds, depending on how long the history has grown and which model is being used. A limit expressed in steps says almost nothing about the two things people actually care about, which are how long they wait and what it costs.
| step | the step limit | one task | a thousand tasks a day | a million tasks a day | what happened |
|---|---|---|---|---|---|
| 1 | 4 steps | 2.2 pence | £22 a day | £22,000 a day | Four tenths plus fifteen hundredths is fifty five hundredths of a penny a step, and that figure is the whole of the arithmetic here. |
| 2 | 12 steps | 6.6 pence | £66 a day | £66,000 a day | Six and a half pence a task sounds like nothing, which is exactly the trouble with reading the second column on its own. |
| 3 | 20 steps | 11.0 pence | £110 a day | £110,000 a day | The step limit mentioned at the top of this lesson. Twenty steps says nothing about money until this sum is done, and then it says rather a lot. |
| 4 | 24 steps | 13.2 pence | £132 a day | £132,000 a day | Doubling the limit from twelve doubles this row, which is the comforting version. The section below is where that stops being true. |
So three budgets, all checked in the loop. Steps, because it is the cheapest to enforce and catches runaway behaviour immediately. Time, because somebody is waiting and a correct answer after four minutes is often worth less than an admission after thirty seconds. And money, because a loop with no cost limit has no upper bound on a bad day and bad days are when it will run.
| catches a stuck loop | protects the person waiting | protects the bill | cheap to enforce | |
|---|---|---|---|---|
| a step limit | 1 | 0 | 0 | 1 |
| a time budget | 1 | 1 | 0 | 1 |
| a cost budget | 0 | 0 | 1 | 0 |
| all three together | 1 | 1 | 1 | 1 |
Why the cost grows faster than the length
The second lesson showed the curve and this is the reasoning behind it.
At step one the model reads the question. At step two it reads the question, the first request and the first result. At step three it reads all of that again plus one more exchange. Nothing is ever read once.
If each step adds about the same amount to the history, then the total read across a task of many steps is the sum of one plus two plus three and so on, which is about half the square of the number of steps. Twice as many steps is roughly four times the reading.
The lesson stops here
3 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents