cloudfoundry/workpool

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

workpool

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.

Example
 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)
})


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.