Async LimiterSourceAsyncLimiterTimingBurstSmooth

module Smooth

Enforces even task distribution to prevent clustering.

Smooth strategies prevent clustering by requiring tasks to wait for frame boundaries, ensuring smooth and predictable task execution timing. This creates consistent load patterns and prevents resource spikes.

Smooth Behavior

Smooth behavior with 3 tasks per 15-second window:

Window 1: [Task1] -- [Task2] -- [Task3] ---- (evenly spaced) 0s 5s 10s 15s Window 2: [Task4] -- [Task5] -- [Task6] ---- (evenly spaced) 15s 20s 25s 30s

Perfect for: API rate limiting, smooth resource usage

Definitions

def self.can_acquire?(window_count, limit, frame_changed)

Check if a task can be acquired in continuous mode.

Signature

parameter window_count Integer

Ignored in continuous mode.

parameter limit Integer

Ignored in continuous mode.

parameter frame_changed Boolean

Whether the frame boundary has been crossed.

returns Boolean

True only if the frame boundary has been crossed.

Implementation

def self.can_acquire?(window_count, limit, frame_changed)
	frame_changed
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

Ignored in continuous mode.

parameter window_duration Numeric

Ignored in continuous mode.

parameter frame_start_time Numeric

When the current frame started.

parameter frame_duration Numeric

Duration of each frame.

returns Numeric

The next frame start time.

Implementation

def self.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration)
	frame_start_time + frame_duration
end

def self.window_blocking?(window_count, limit, window_changed)

Check if window constraints are blocking new tasks.

Signature

parameter window_count Integer

Ignored in continuous mode.

parameter limit Integer

Ignored in continuous mode.

parameter window_changed Boolean

Ignored in continuous mode.

returns Boolean

Always false for continuous mode.

Implementation

def self.window_blocking?(window_count, limit, window_changed)
	false  # Continuous mode doesn't use window blocking
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

True if frame hasn't changed (blocking until next frame).

Implementation

def self.frame_blocking?(frame_changed)
	!frame_changed
end

def self.statistics

Get current burst strategy statistics.

Signature

returns Hash

Statistics hash with current state.

Implementation

def self.statistics
	{
		name: "Smooth",
	}
end