Documentation ¶
Overview ¶
Package concurrentlimit limits the number of concurrent requests to a Go HTTP or gRPC server.
Index ¶
- Variables
- func Handler(limiter Limiter, handler http.Handler) http.Handler
- func Listen(network string, address string, connectionLimit int) (net.Listener, error)
- func ListenAndServe(srv *http.Server, requestLimit int, connectionLimit int) error
- func ListenAndServeTLS(srv *http.Server, certFile string, keyFile string, requestLimit int, ...) error
- type Limiter
Constants ¶
This section is empty.
Variables ¶
var ErrLimited = errors.New("exceeded max concurrent operations limit")
ErrLimited is returned by Limiter when the concurrent operation limit is exceeded.
Functions ¶
func Handler ¶
Handler returns an http.Handler that uses limiter to only permit a limited number of concurrent requests to be processed.
func ListenAndServe ¶
ListenAndServe listens for HTTP requests with a limited number of concurrent requests and connections. This helps avoid running out of memory during overload situations. Both requestLimit and connectionLimit must be > 0, and connectionLimit must be >= requestLimit. A reasonable defalt is to set the connectionLimit to double the request limit, which assumes that processing each request requires more memory than a raw connection, and that keeping some idle connections is useful. This modifies srv.Handler with another handler that implements the limit.
This also sets the server's ReadHeaderTimeout and IdleTimeout to a reasonable default if they are not set, which is an attempt to avoid idle or slow connections using all connections.
func ListenAndServeTLS ¶
func ListenAndServeTLS( srv *http.Server, certFile string, keyFile string, requestLimit int, connectionLimit int, ) error
ListenAndServeTLS listens for HTTP requests with a limited number of concurrent requests and connections. See the documentation for ListenAndServe for details.
Types ¶
type Limiter ¶
type Limiter interface { // Start begins a new operation. It returns a completion function that must be called when the // operation completes, or it returns ErrLimited if no more concurrent operations are allowed. // This should be called as: // // end, err := limiter.Start() // if err != nil { // // Handle ErrLimited // defer end() Start() (func(), error) }
Limiter limits the number of concurrent operations that can be processed.
Directories ¶
Path | Synopsis |
---|---|
Package grpclimit limits the number of concurrent requests and concurrent connections to a gRPC server to ensure that it does not run out of memory during overload scenarios.
|
Package grpclimit limits the number of concurrent requests and concurrent connections to a gRPC server to ensure that it does not run out of memory during overload scenarios. |
Package sleepymemory contains protobuf messages.
|
Package sleepymemory contains protobuf messages. |