resource

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package resource defines server configuration, resource limits, and default presets. The top-level celeris.Config is the primary user-facing type; this package provides the internal representation used by engine implementations.

Index

Constants

View Source
const (
	// MinWorkers is the minimum allowed number of I/O workers.
	MinWorkers = 2
	// MaxSQERing is the maximum io_uring submission queue ring size.
	MaxSQERing = 65536
	// MinBufferSize is the minimum per-connection I/O buffer size in bytes.
	MinBufferSize = 4096
	// MaxBufferSize is the maximum per-connection I/O buffer size in bytes.
	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 is the HTTP protocol version (HTTP1, H2C, or Auto).
	Protocol engine.Protocol
	// Engine is the I/O engine type (IOUring, Epoll, Adaptive, or Std).
	Engine engine.EngineType
	// Addr is the TCP address to listen on (e.g. ":8080").
	Addr string
	// Resources holds worker, buffer, and connection limit overrides.
	Resources Resources
	// MaxHeaderBytes is the max header block size in bytes (min 4096 if set).
	MaxHeaderBytes int
	// MaxConcurrentStreams limits simultaneous H2 streams per connection.
	MaxConcurrentStreams uint32
	// MaxFrameSize is the max H2 frame payload size (range 16384-16777215).
	MaxFrameSize uint32
	// InitialWindowSize is the H2 initial stream flow-control window size.
	InitialWindowSize uint32
	// ReadTimeout is the max duration for reading the entire request.
	ReadTimeout time.Duration
	// WriteTimeout is the max duration for writing the response.
	WriteTimeout time.Duration
	// IdleTimeout is the max duration a keep-alive connection may be idle.
	IdleTimeout time.Duration
	// DisableKeepAlive disables HTTP keep-alive.
	DisableKeepAlive bool
	// Listener is an optional pre-existing listener for socket inheritance.
	Listener net.Listener
	// MaxRequestBodySize is the maximum allowed request body size in bytes.
	// 0 uses the default (100 MB). -1 disables the limit (unlimited).
	MaxRequestBodySize int64
	// OnExpectContinue is called when an H1 request contains "Expect: 100-continue".
	// If the callback returns false, the server responds with 417 Expectation Failed
	// and skips reading the request body. If nil, the server always sends 100 Continue.
	OnExpectContinue func(method, path string, headers [][2]string) bool
	// OnConnect is called when a new connection is accepted.
	OnConnect func(addr string)
	// OnDisconnect is called when a connection is closed.
	OnDisconnect func(addr string)
	// Logger is the structured logger for engine diagnostics (default slog.Default()).
	Logger *slog.Logger
}

Config holds the internal server configuration used by engine implementations. Users typically interact with the top-level celeris.Config instead.

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 ResolvedResources

type ResolvedResources struct {
	// Workers is the resolved number of I/O worker goroutines.
	Workers int
	// SQERingSize is the io_uring submission queue size (power of 2).
	SQERingSize int
	// BufferPool is the number of pre-allocated I/O buffers.
	BufferPool int
	// BufferSize is the resolved per-connection I/O buffer size in bytes.
	BufferSize int
	// MaxEvents is the max events returned per epoll_wait call.
	MaxEvents int
	// MaxConns is the resolved max connections per worker.
	MaxConns int
	// SocketRecv is the resolved SO_RCVBUF size.
	SocketRecv int
	// SocketSend is the resolved SO_SNDBUF size.
	SocketSend int
}

ResolvedResources contains the final computed values after applying defaults, user overrides, and hard caps. Used by engine implementations at startup.

type Resources

type Resources struct {
	// Workers is the number of I/O worker goroutines (0 = GOMAXPROCS).
	Workers int
	// BufferSize is the per-connection I/O buffer size in bytes (0 = engine default).
	BufferSize int
	// SocketRecv is the SO_RCVBUF size for accepted connections (0 = OS default).
	SocketRecv int
	// SocketSend is the SO_SNDBUF size for accepted connections (0 = OS default).
	SocketSend int
	// MaxConns is the max simultaneous connections per worker (0 = unlimited).
	MaxConns int
}

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

func (Resources) Resolve

func (r Resources) Resolve() ResolvedResources

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

Jump to

Keyboard shortcuts

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