lib/rack/throttle/limiters/sliding_window.rb in improved-rack-throttle-0.7.0 vs lib/rack/throttle/limiters/sliding_window.rb in improved-rack-throttle-0.7.1
- old
+ new
@@ -16,13 +16,12 @@
options[:burst] ||= 5
options[:average] ||= 1
end
##
- # Returns `true` if sufficient time (equal to or more than
- # {#minimum_interval}) has passed since the last request and the given
- # present `request`.
+ # Returns `true` if the request conforms to the
+ # specified :average and :burst rules
#
# @param [Rack::Request] request
# @return [Boolean]
def allowed?(request)
t1 = request_start_time(request)
@@ -43,13 +42,21 @@
# This prevents the Rack application blowing up merely due to a
# backend cache server (Memcached, Redis, etc.) being offline.
end
end
+ ###
+ # LeakyBucket is an internal class used to implement the
+ # SlidingWindow limiter strategy. It is a (slightly tweaked)
+ # implementation of the {http://en.wikipedia.org/wiki/Leaky_bucket
+ # Leaky Bucket Algorithm}.
class LeakyBucket
attr_accessor :maximum, :outflow
attr_reader :count, :last_touched
+ ##
+ # @param [Integer] maximum
+ # @param [Float] outflow
def initialize(maximum, outflow)
@maximum, @outflow = maximum, outflow
@count, @last_touched = 0, Time.now
end