Breakdowns
Level: Advanced
Make a resource fail at random and be repaired, decide what happens to the work it was doing, and check how long it was down. It builds on Interruptions, which explains on_interrupt, and on Resources, which describes the down state.
Steps
- Give the resource a
breakdownwith two distributions:time_to_failure, the time from the start or from a repair to the next failure, andrepair, how long a repair takes. - Choose
work:interrupt, the default, stops the tasks being served when the resource fails;finishlets them finish and stops only new work. - With
interrupt, give the task anon_interrupt:resumepacks what was left after the repair,restartpacks again from the start, andabandonends the order.
Here a packing station of two units fails about once a minute and takes 5 to 15 seconds to repair:
| examples/low-level/breakdowns_example.py:station | |
|---|---|
The breakdowns run as a SimPy process, started beside the arrivals:
| examples/low-level/breakdowns_example.py:processes | |
|---|---|
An interrupted order catches simpy.Interrupt, whose cause is "breakdown", gives back its request and asks again, as the full file shows.
The failure clock runs on calendar time: the next failure is drawn at the start and after each repair, whether the station is busy or idle. While the station is down its capacity is 0, so no order starts, and every unit fails together. Its current_cap keeps the planned value: a scenario step or an ingress message that changes it during the repair sets the capacity the station returns to, and does not end the repair. The station publishes an event keyed by its name at each failure, {"status": "down", "reason": "failure"}, and at each repair, {"status": "repaired", "reason": "failure"}. The two distributions are registry paths, Shop.breakdown.station.time_to_failure and .repair, so a live change can make failures more or less frequent.
A breakdown that lets work finish and then holds the resource for a fixed time each day is a capacity schedule; Time-varying Arrivals writes it as scenario steps.
Check the Downtime
With statistics at minimal or above, the station publishes down, 1 while it is down and 0 otherwise; from basic, downtime, the seconds it has been down, and failures, how many times it has failed. This function runs the example, finds the down periods from the events, and checks both counts against them:
For the example it returns five down periods, the first from 84.6 to 98.5 seconds, 52.5 seconds of downtime in 300 (17.5 percent), and 8 orders interrupted, all 8 resumed after a repair. Report the downtime beside the waits: a station that is down 17.5 percent of the time has that much less capacity, and its waits grow as on Queues and Capacity.
Example
The breakdowns example is the model above: two units at a packing station, orders at 0.6 a second, and every order packed once the station is back. It needs no Docker service and ends on its own after 300 simulation seconds.
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip:
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip:
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip: