maxconnections

package
v3.7.0-0.133.0+incompa... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	OverloadHandler http.Handler
	// contains filtered or unexported fields
}

Handler implements the http.Handler interface.

func New

func New(limiter Limiter, h http.Handler) *Handler

New returns an http.Handler that uses limiter to control h invocation. If limiter prohibits starting a new handler, OverloadHandler will be invoked.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Limiter

type Limiter interface {
	// Start decides whether a new job can be started. The decision may be
	// returned after a delay if the limiter wants to throttle jobs.
	Start(context.Context) bool

	// Done must be called when a job is finished.
	Done()
}

A Limiter controls starting of jobs.

func NewLimiter

func NewLimiter(maxRunning, maxInQueue int, maxWaitInQueue time.Duration) Limiter

NewLimiter return a limiter that allows no more than maxRunning jobs at the same time. It can enqueue up to maxInQueue jobs awaiting to be run, and a job may wait in the queue no more than maxWaitInQueue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL