Name: workpool
Owner: Cloud Foundry
Description: null
Created: 2016-09-14 17:28:48.0
Updated: 2017-05-03 02:55:54.0
Pushed: 2017-07-19 18:33:44.0
Homepage: null
Size: 11
Language: Go
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Import this package via code.cloudfoundry.org/workpool
.
Use a WorkPool
to perform units of work concurrently at a maximum rate. The worker goroutines will increase to the maximum number of workers as work requires it, and gradually decrease to 0 if unused.
A Throttler
performs a specified batch of work at a given maximum rate, internally creating a WorkPool
and then stopping it when done.
RateLimitingHandler struct {
backend http.Handler
pool *workpool.WorkPool
nsures that the backend handler never processes more than maxInFlight requests at a time
NewRateLimitingHandler(backend http.Handler, maxInFlight int) (*RateLimitingHandler, error) {
pool, err := workpool.NewWorkPool(maxInFlight)
if err != nil {
return nil, err
}
return &RateLimitingHandler{
backend: backend,
pool: pool,
}, nil
(rh *RateLimitingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
rh.pool.Submit(func() {
rh.backend.ServeHTTP(w, req)
})