Module: Async::Limiter::Timing::Burst::Smooth

Defined in:
lib/async/limiter/timing/burst.rb

Overview

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

Class Method Summary collapse

Class Method Details

.can_acquire?(window_count, limit, frame_changed) ⇒ Boolean

Check if a task can be acquired in continuous mode.

Returns:

  • (Boolean)


112
113
114
# File 'lib/async/limiter/timing/burst.rb', line 112

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

.frame_blocking?(frame_changed) ⇒ Boolean

Check if frame constraints are blocking new tasks.

Returns:

  • (Boolean)


138
139
140
# File 'lib/async/limiter/timing/burst.rb', line 138

def self.frame_blocking?(frame_changed)
	!frame_changed
end

.next_acquire_time(window_start_time, window_duration, frame_start_time, frame_duration) ⇒ Object

Calculate the next time a task can be acquired.



122
123
124
# File 'lib/async/limiter/timing/burst.rb', line 122

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

.statisticsObject

Get current burst strategy statistics.



144
145
146
147
148
# File 'lib/async/limiter/timing/burst.rb', line 144

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

.window_blocking?(window_count, limit, window_changed) ⇒ Boolean

Check if window constraints are blocking new tasks.

Returns:

  • (Boolean)


131
132
133
# File 'lib/async/limiter/timing/burst.rb', line 131

def self.window_blocking?(window_count, limit, window_changed)
	false  # Continuous mode doesn't use window blocking
end