macOS sleep behavior
What happens to background jobs when your Macbook goes to sleep?
I ran some experiments on my laptop (macOS Sequoia 15.6.1) with a background job scheduled to run every minute.
Scenario | N | Mean interval | Max interval |
---|---|---|---|
Lid open, with power | 129 | 3m28s | 18m3s |
Lid open, no power | 42 | 11m5s | 120m45s |
Lid closed, with power | 305 | 2m0s | 17m28s |
Lid closed, no power | 4 | 117m13s | 147m20s |
I ran these overnight, so the durations aren't exactly equal.
The test job is spawned by a daemon that it itself run by Launchd. I don't know if that extra layer of indirection affects the results at all.
My takeaways:
- Even with lid closed and no power, the user processes don't completely go to sleep.
- Background jobs will run a lot more frequently if the laptop is plugged in.
The original impetus for this experiment was flaky DNS failures for services on my Tailscale VPN. HTTP requests to the outside world always succeeded, so it must be something particular to my Tailscale set-up. If you have any ideas, let me know!