MCPcopy Index your code
hub / github.com/koding/kite / Throttle

Method Throttle

method.go:111–123  ·  view source on GitHub ↗

Throttle throttles the method for each incoming request. The throttle algorithm is based on token bucket implementation: http://en.wikipedia.org/wiki/Token_bucket. Rate determines the number of request which are allowed per frequency. Example: A capacity of 50 and fillInterval of two seconds means t

(fillInterval time.Duration, capacity int64)

Source from the content-addressed store, hash-verified

109// example to have throttle with 30 req/second, you need to have a fillinterval
110// of 33.33 milliseconds.
111func (m *Method) Throttle(fillInterval time.Duration, capacity int64) *Method {
112 // don't do anything if the bucket is initialized already
113 if m.bucket != nil {
114 return m
115 }
116
117 m.bucket = ratelimit.NewBucket(
118 fillInterval, // interval
119 capacity, // token per interval
120 )
121
122 return m
123}
124
125// PreHandler adds a new kite handler which is executed before the method.
126func (m *Method) PreHandle(handler Handler) *Method {

Callers 1

TestMethod_ThrottlingFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestMethod_ThrottlingFunction · 0.64