Skip to content

feat(runtime): add autoscaler for automatic worker thread scaling#29

Merged
Coldwings merged 2 commits intomainfrom
feature/autoscaler
Feb 24, 2026
Merged

feat(runtime): add autoscaler for automatic worker thread scaling#29
Coldwings merged 2 commits intomainfrom
feature/autoscaler

Conversation

@Coldwings
Copy link
Owner

Summary

  • Add autoscaler component for automatic worker thread scaling
  • Support overload scale-up, idle scale-down, and block detection
  • Template-based trigger-action system with combinators (on_success, on_failure)
  • Configurable thresholds: tick_interval, overload_threshold, idle_threshold, idle_delay, min/max_workers, block_threshold

Test Plan

  • All 830 standard tests pass
  • All ASAN tests pass
  • All TSAN tests pass

Implement two new synchronization primitives:

- spinlock: TTAS (Test-and-Test-and-Set) algorithm with CPU pause
  instructions for efficient spinning. Includes spinlock_guard with
  RAII, move semantics, and manual unlock support.

- condition_variable: Coroutine-aware condition variable that suspends
  instead of blocking. Supports three usage modes:
  - With mutex (double co_await pattern for async re-lock)
  - With spinlock/lockable (single co_await, sync re-lock)
  - Unlocked mode for single-worker-thread scenarios
  Provides notify_one() and notify_all() via scheduler handle
  rescheduling.

Includes comprehensive tests (12 test cases) covering basic operations,
coroutine integration, RAII guards, move semantics, producer-consumer
patterns, and notify_one/notify_all semantics. All tests pass under
ASAN and TSAN with no warnings.

Updates wiki documentation (API-Reference.md, Core-Concepts.md) with
full API signatures, usage examples, and design guidance.
Add autoscaler component that automatically adjusts worker thread count
based on load. Includes:

- autoscaler_config: Configurable thresholds for scaling decisions
- autoscaler_triggers: Template-based trigger types (on_overload, on_idle, on_block)
- autoscaler_actions: Action types and combinators (scale_up, scale_down, log, null)
- autoscaler_impl: Main autoscaler with default trigger behavior

Features:
- Automatic scale-up when pending tasks exceed overload threshold
- Automatic scale-down when queue is idle for configured delay
- Block detection for workers stuck in user code
- Template-based trigger-action system for extensibility
- Default behavior works without custom triggers

Add worker metrics tracking (last_task_time, is_idle) to support
autoscaler block detection.

Update examples, documentation, and tests.
@Coldwings Coldwings merged commit d9901e7 into main Feb 24, 2026
4 checks passed
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