leastconn

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package leastconn provides a balancer based on the least connections.

Index

Constants

This section is empty.

Variables

View Source
var GetConcurrency func(loadbalancer.Endpoint) int = func(e loadbalancer.Endpoint) int {
	if c, ok := e.(Concurrenter); ok {
		return c.Concurrent()
	}
	return 0
}

GetConcurrency is the default function to get the concurrency number of the endpoint.

For the default implementation, check whether the endpoint has implemented the interface Concurrenter and call it. Or, return 0.

Functions

This section is empty.

Types

type Balancer

type Balancer struct {
	// contains filtered or unexported fields
}

Balancer implements the balancer based on the least number of the connection.

func NewBalancer

func NewBalancer(policy string, getconcurrency func(loadbalancer.Endpoint) int) *Balancer

NewBalancer returns a new balancer based on the random with the policy name.

If policy is empty, use "leastconn" instead. If getconcurrency is nil, use GetConcurrency instead.

func (*Balancer) Forward

func (b *Balancer) Forward(c context.Context, r any, eps *loadbalancer.Static) (any, error)

Forward forwards the request to one of the backend endpoints.

func (*Balancer) Policy

func (b *Balancer) Policy() string

Policy returns the policy of the balancer.

type Concurrenter added in v0.8.0

type Concurrenter interface {
	Concurrent() int
}

Concurrenter is used to return the concurrent number of an endpoint.

Jump to

Keyboard shortcuts

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