resource

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package resource defines configuration presets and performance profiles.

Index

Constants

View Source
const (
	MinWorkers    = 2
	MaxSQERing    = 65536
	MinBufferSize = 4096
	MaxBufferSize = 262144
)

Resource limit constants for validation and clamping.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Protocol             engine.Protocol
	Engine               engine.EngineType
	Addr                 string
	Resources            Resources
	Objective            ObjectiveProfile
	MaxHeaderBytes       int
	MaxConcurrentStreams uint32
	MaxFrameSize         uint32
	InitialWindowSize    uint32
	ReadTimeout          time.Duration
	WriteTimeout         time.Duration
	IdleTimeout          time.Duration
	DisableKeepAlive     bool
	Overload             overload.Config
	Logger               *slog.Logger
}

Config holds server configuration including protocol, engine, address, and resource settings.

func (Config) Validate

func (c Config) Validate() []error

Validate checks all config fields and returns any validation errors.

func (Config) WithDefaults

func (c Config) WithDefaults() Config

WithDefaults returns a copy of Config with zero-value fields set to sensible defaults.

type ObjectiveParams

type ObjectiveParams struct {
	CQBatch      int
	EpollTimeout time.Duration
	SOBusyPoll   time.Duration
	BufferSize   int
	SQERingScale int
	Write        WriteStrategy
	SQPollIdle   time.Duration
	TCPNoDelay   bool
	TCPQuickAck  bool
}

ObjectiveParams holds the resolved I/O and networking parameters for an objective profile.

func ResolveObjective

func ResolveObjective(profile ObjectiveProfile) ObjectiveParams

ResolveObjective returns the concrete I/O parameters for the given objective profile.

type ObjectiveProfile

type ObjectiveProfile uint8

ObjectiveProfile selects a tuning profile that controls I/O and networking parameters.

const (
	BalancedObjective ObjectiveProfile = iota
	LatencyOptimized
	ThroughputOptimized
)

Objective profile constants for server tuning.

func (ObjectiveProfile) String

func (o ObjectiveProfile) String() string

type ResolvedResources

type ResolvedResources struct {
	Workers     int
	SQERingSize int
	BufferPool  int
	BufferSize  int
	MaxEvents   int
	MaxConns    int
	SocketRecv  int
	SocketSend  int
}

ResolvedResources contains the final computed values after applying presets and overrides.

type ResourcePreset

type ResourcePreset uint8 //nolint:revive // ResourcePreset is clearer than Preset for cross-package use

ResourcePreset selects a predefined resource allocation profile.

const (
	Greedy ResourcePreset = iota
	Balanced
	Minimal
)

Resource preset constants.

func (ResourcePreset) String

func (p ResourcePreset) String() string

type Resources

type Resources struct {
	Preset      ResourcePreset
	Workers     int
	SQERingSize int
	BufferPool  int
	BufferSize  int
	MaxEvents   int
	MaxConns    int
	SocketRecv  int
	SocketSend  int
}

Resources allows user overrides of preset values. Zero values mean "use preset default".

func (Resources) Resolve

func (r Resources) Resolve(numCPU int) ResolvedResources

Resolve applies preset defaults, user overrides, and hard caps.

type WriteStrategy

type WriteStrategy uint8

WriteStrategy controls whether writes are issued immediately or batched.

const (
	WriteImmediate WriteStrategy = iota
	WriteBatched
)

Write strategy constants.

func (WriteStrategy) String

func (w WriteStrategy) String() string

Jump to

Keyboard shortcuts

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