Skip to content

Debounce scale-to-zero re-enable on DebouncedController#220

Draft
sjmiller609 wants to merge 1 commit intomainfrom
hypeship/debounce-stz-reenable
Draft

Debounce scale-to-zero re-enable on DebouncedController#220
sjmiller609 wants to merge 1 commit intomainfrom
hypeship/debounce-stz-reenable

Conversation

@sjmiller609
Copy link
Copy Markdown
Contributor

Summary

Adds a configurable cooldown to the scale-to-zero DebouncedController. When the last active request completes, the re-enable is delayed by the cooldown period instead of firing immediately. If a new request arrives during the cooldown window, the pending re-enable is cancelled and STZ stays disabled.

This reduces the rate of control file toggling under rapid sequential request patterns while preserving correctness — STZ is always disabled when there's an active request, and always re-enabled after a quiet period.

The cooldown is set to 1 second. Zero cooldown preserves the original synchronous behavior.

Changes

  • NewDebouncedControllerWithCooldown(ctrl, cooldown) — new constructor with configurable cooldown
  • DebouncedController.Enable — schedules a timer-based re-enable when cooldown > 0
  • DebouncedController.Disable — cancels any pending re-enable timer
  • main.go — uses 1s cooldown

Test plan

  • Existing tests pass (backward compat with zero cooldown)
  • New test: cooldown delays the enable write
  • New test: new Disable cancels pending re-enable timer
  • New test: rapid sequential requests collapse to single Disable/Enable pair
  • New test: zero cooldown behaves identically to original

The existing DebouncedController uses reference counting to coalesce
concurrent Disable/Enable calls, but sequential requests each trigger
a full Disable→Enable cycle on the control file.

Add an optional cooldown duration: when the last active holder releases,
the re-enable is delayed by the cooldown period. If a new Disable
arrives before the timer fires, the pending re-enable is cancelled.
This collapses rapid sequential requests into a single Disable/Enable
pair.

The cooldown is set to 1 second, which is long enough to collapse
back-to-back request patterns while adding negligible delay to the
VM's ability to enter standby.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant