Module: Async::Limiter::Timing::Burst::Greedy
- Defined in:
- lib/async/limiter/timing/burst.rb
Overview
Allows tasks to cluster within windows for high-throughput scenarios.
Greedy strategies permit multiple tasks to start immediately as long as the window limit hasn’t been exceeded. This creates “bursts” of activity at window boundaries, maximizing throughput when resources become available.
## Greedy Behavior
Greedy behavior with 3 tasks per 10-second window:
Window 1: [Task1, Task2, Task3] at 0s -------- (all immediate)
Window 2: [Task4, Task5, Task6] at 10s ------- (all immediate)
Perfect for: Batch processing, high-throughput scenarios
Class Method Summary collapse
-
.can_acquire?(window_count, limit, frame_changed) ⇒ Boolean
Check if a task can be acquired in burstable mode.
-
.frame_blocking?(frame_changed) ⇒ Boolean
Check if frame constraints are blocking new tasks.
-
.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration) ⇒ Object
Calculate the next time a task can be acquired.
-
.statistics ⇒ Object
Get current burst strategy statistics.
-
.window_blocking?(window_count, limit, window_changed) ⇒ Boolean
Check if window constraints are blocking new tasks.
Class Method Details
.can_acquire?(window_count, limit, frame_changed) ⇒ Boolean
Check if a task can be acquired in burstable mode.
50 51 52 |
# File 'lib/async/limiter/timing/burst.rb', line 50 def self.can_acquire?(window_count, limit, frame_changed) window_count < limit end |
.frame_blocking?(frame_changed) ⇒ Boolean
Check if frame constraints are blocking new tasks.
77 78 79 |
# File 'lib/async/limiter/timing/burst.rb', line 77 def self.frame_blocking?(frame_changed) false # Burstable mode doesn't use frame blocking end |
.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration) ⇒ Object
Calculate the next time a task can be acquired.
60 61 62 |
# File 'lib/async/limiter/timing/burst.rb', line 60 def self.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration) window_start_time + window_duration end |
.statistics ⇒ Object
Get current burst strategy statistics.
83 84 85 86 87 |
# File 'lib/async/limiter/timing/burst.rb', line 83 def self.statistics { name: "Greedy", } end |
.window_blocking?(window_count, limit, window_changed) ⇒ Boolean
Check if window constraints are blocking new tasks.
69 70 71 72 |
# File 'lib/async/limiter/timing/burst.rb', line 69 def self.window_blocking?(window_count, limit, window_changed) return false if window_changed window_count >= limit end |