We Estimated 3-5 Minutes of Maintenance Downtime. I Measured It: 61 Seconds
What happened
While planning a library update for a production PHP site, I was asked a simple question: "How long will the site be down during the composer update?" I answered "about 3 to 5 minutes."
My basis for that number was... nothing. One or two minutes for composer downloads, a minute for cache regeneration, some tens of seconds for a restart - arithmetic done entirely in my head. That number was about to become the basis for a "10-minute maintenance window" announcement.
And then it hit me: I had never actually measured the real downtime. On the previous update, my only verification was "I opened the page afterward and it rendered." Reporting a number I'd never measured felt wrong, so I decided to measure it properly once, on the dev server.
Why nobody ever measures this
Once you try, you realize the logs of a typical update job are not built for measuring downtime.
First, composer's log has no timestamped boundary between downloading and installing. The output of composer update is just a stream of progress lines - you can't tell where the vendor rewrite begins, which is exactly the point where the site can start breaking.
Second, the "moment of recovery" leaves no record either. With the maintenance page ON, curl-based monitoring only sees the maintenance 503. The time when the actual application first returned 200 is unobservable unless you punch through the maintenance page to the app itself.
In other words, with a normal workflow neither the start time nor the end time exists in any log - so nobody measures, and the estimate keeps circulating on its own.
The fix: an elapsed-seconds log on every step
I defined one log function at the top of the update script and wrapped every step with it.
T0=$(date +%s)
log(){ echo "[$(date -u +%H:%M:%S) +$(( $(date +%s)-T0 ))s] $*"; }
log "maintenance page ON"
touch /path/to/app/maintenance.flag
TM=$(date +%s) # ← stopwatch for downtime starts here
log "composer update start"
composer update --no-scripts 2>&1 | tee /tmp/composer.log
log "composer update done"
log "cache rebuild"
sudo -u apache php bin/console cache:clear --no-warmup
sudo -u apache php bin/console cache:warmup
log "httpd restart"
systemctl restart httpd
Three points matter here.
- Capture
TM=$(date +%s)immediately after maintenance ON. I defined downtime as "from the moment the maintenance flag is raised until the app first returns 200." Forget to capture this origin and no amount of log reading will reconstruct it. - Detect recovery with a bypass-cookie curl. The maintenance page has an internal bypass (a specific cookie lets you through), so a loop hits the real app directly:
until curl -s -o /dev/null -w '%{http_code}' \
-b 'maintenance_bypass=1' https://dev.example.com/ | grep -q 200; do sleep 1 done
log "recovered: downtime $(( $(date +%s)-TM ))s"
- Slice the composer log by line content. Since there are no timestamps, use the
Lock file operations:andPackage operations:lines to separate the resolution phase from the write phase, and treat the first- Upgradingline as "vendor rewrite begins = unavailability begins." Now you can read, after the fact, how many seconds went to downloads versus the dangerous window.
The result: 61 seconds - a third of the estimate
Here's the actual measurement on the dev server:
[07:42:01 +0s] maintenance page ON
[07:42:02 +1s] composer update start
[07:42:53 +52s] composer update done
[07:42:55 +54s] cache rebuild
[07:43:01 +60s] httpd restart
[07:43:02 +61s] recovered: downtime 61s
61 seconds total, of which the vendor rewrite took about 50. One third of the "3 to 5 minutes" estimate.
One caveat: this number was taken with a warm composer cache (~60 MB). With the cache cleared, downloads added tens of seconds. The number you use for production must be measured under production-like cache conditions.
Armed with "61 seconds measured," the maintenance announcement shrank from a 10-minute window to a 5-minute one, and the report could say "measured 61s (5-minute window with margin)." A measured number argues very differently from an estimated one.
Takeaways
- Don't estimate downtime. One measurement on dev gives you a real number, and that number becomes both the window length and the basis of your report
- The instrumentation is tiny: one log function, the TM origin capture, and a bypass-cookie curl loop - about ten lines added to an existing script
- Composer's log tells you neither times nor phases. Slice it yourself with
Lock file operations/Package operations/ the first- Upgradingline - Warm vs. cold cache changes the number by tens of seconds. Measure under the same conditions you'll run in production
There was one more byproduct. I had been considering a zero-downtime scheme (build vendor beside the live one, swap with mv). The moment I knew the current state was 61 seconds, I deprioritized it. Start "improving" without knowing where you are, and you walk straight into over-engineering. The stopwatch turned out to be a tool you should pick up before the optimization, not after.
Comments
No comments yet. Start the discussion.