Class: Async::Limiter::Timing::FixedWindow
- Inherits:
-
SlidingWindow
- Object
- SlidingWindow
- Async::Limiter::Timing::FixedWindow
- Defined in:
- lib/async/limiter/timing/fixed_window.rb
Overview
Fixed window timing strategy with discrete boundaries aligned to clock time.
Fixed windows reset at specific intervals (e.g., every minute at :00 seconds), creating predictable timing patterns and allowing bursting at window boundaries.
Instance Attribute Summary
Attributes inherited from SlidingWindow
#Duration of the timing window in seconds., #Maximum tasks allowed per window., #duration, #limit
Instance Method Summary collapse
-
#statistics ⇒ Object
Get current timing strategy statistics.
-
#window_start_time(current_time) ⇒ Object
Calculate the start time of the fixed window containing the given time.
Methods inherited from SlidingWindow
#acquire, #can_acquire?, #initialize, #maximum_cost, #wait, #window_changed?
Constructor Details
This class inherits a constructor from Async::Limiter::Timing::SlidingWindow
Instance Method Details
#statistics ⇒ Object
Get current timing strategy statistics.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/async/limiter/timing/fixed_window.rb', line 28 def statistics { name: "FixedWindow", window_duration: @duration, window_limit: @limit, current_window_count: @window_count, window_utilization_percentage: (@window_count.to_f / @limit) * 100, burst: @burst.statistics, } end |
#window_start_time(current_time) ⇒ Object
Calculate the start time of the fixed window containing the given time.
22 23 24 |
# File 'lib/async/limiter/timing/fixed_window.rb', line 22 def window_start_time(current_time) (current_time / @duration).to_i * @duration end |