backend

package
v0.0.0-...-a87a7cb Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package backend tracks a set of inference backends grouped by the models they serve, health-checks them, and hands out the next healthy one for a given model in round-robin order.

Index

Constants

View Source
const (
	RoundRobin   = "round_robin"
	LeastPending = "least_pending"
	Weighted     = "weighted"
)

Load-balancing strategies, as accepted in the "load_balancing" config key.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Name       string
	URL        *url.URL
	PathPrefix string
	APIKey     string
	Models     []string
	Weight     int
	// contains filtered or unexported fields
}

func (*Backend) Healthy

func (b *Backend) Healthy() bool

type Pool

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

func NewPool

func NewPool(specs []config.Backend, strategy ...string) (*Pool, error)

NewPool builds a pool from specs. strategy is one of RoundRobin (the default when empty or unrecognised), LeastPending, or Weighted.

func (*Pool) MarkUnhealthy

func (p *Pool) MarkUnhealthy(b *Backend)

func (*Pool) Models

func (p *Pool) Models() []string

Models returns every model name any backend in the pool serves, sorted and de-duplicated. Backs the OpenAI-compatible GET /v1/models.

func (*Pool) Next

func (p *Pool) Next(model string) (*Backend, func(), error)

Next returns a healthy backend serving model, chosen by the pool's load-balancing strategy, plus a release func the caller must call once it has finished proxying to that backend (it decrements the in-flight count the least_pending strategy reads; a no-op for the others). It returns an error if no backend serves the model or all of them are currently unhealthy.

func (*Pool) Snapshot

func (p *Pool) Snapshot() []Status

Snapshot returns the current health of every backend in the pool.

func (*Pool) StartHealthChecks

func (p *Pool) StartHealthChecks(ctx context.Context, path string, interval time.Duration)

StartHealthChecks polls every backend's health path on interval and updates its healthy flag until ctx is canceled.

type Status

type Status struct {
	Name    string   `json:"name"`
	URL     string   `json:"url"`
	Models  []string `json:"models"`
	Healthy bool     `json:"healthy"`
}

Status is a point-in-time snapshot of one backend, for introspection.

Jump to

Keyboard shortcuts

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