module Greedy
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
Definitions
def self.can_acquire?(window_count, limit, frame_changed)
Check if a task can be acquired in burstable mode.
Signature
-
parameter
window_count
Integer
Number of tasks started in current window.
-
parameter
limit
Integer
Maximum tasks allowed in the window.
-
parameter
frame_changed
Boolean
Ignored in burstable mode.
-
returns
Boolean
True if under the window limit.
Implementation
def self.can_acquire?(window_count, limit, frame_changed)
window_count < limit
end
def self.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration)
Calculate the next time a task can be acquired.
Signature
-
parameter
window_start_time
Numeric
When the current window started.
-
parameter
window_duration
Numeric
Duration of the window.
-
parameter
frame_start_time
Numeric
Ignored in burstable mode.
-
parameter
frame_duration
Numeric
Ignored in burstable mode.
-
returns
Numeric
The next window start time.
Implementation
def self.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration)
window_start_time + window_duration
end
def self.window_blocking?(window_count, limit, window_changed)
Check if window constraints are blocking new tasks.
Signature
-
parameter
window_count
Integer
Number of tasks started in current window.
-
parameter
limit
Integer
Maximum tasks allowed in the window.
-
parameter
window_changed
Boolean
Whether the window has reset.
-
returns
Boolean
True if window is blocking new tasks.
Implementation
def self.window_blocking?(window_count, limit, window_changed)
return false if window_changed
window_count >= limit
end
def self.frame_blocking?(frame_changed)
Check if frame constraints are blocking new tasks.
Signature
-
parameter
frame_changed
Boolean
Whether the frame boundary has been crossed.
-
returns
Boolean
Always false for burstable mode.
Implementation
def self.frame_blocking?(frame_changed)
false # Burstable mode doesn't use frame blocking
end
def self.statistics
Get current burst strategy statistics.
Signature
-
returns
Hash
Statistics hash with current state.
Implementation
def self.statistics
{
name: "Greedy",
}
end