Documentation
¶
Index ¶
- Variables
- func EmitDeprecation(w io.Writer, name, replacement, url string)
- func GenerateSelfSignedCert(org string, hosts ...string) (tls.Certificate, error)
- func GetHostname() string
- func HashString64(s string) uint64
- func PanicOrigin() string
- func RandomString(length int) string
- func Recover() bool
- func ReleaseBuffer(b *Buffer)
- func ReleaseTimer(t *time.Timer)
- func TakeTimer() *time.Timer
- func Verbose() bool
- type BiMap
- type Buffer
- func CompressGZIP(src *Buffer, preallocate uint, level int) (dst *Buffer, err error)
- func CompressLZW(src *Buffer, preallocate uint) (dst *Buffer, err error)
- func CompressZLIB(src *Buffer, preallocate uint) (dst *Buffer, err error)
- func DecompressGZIP(src *Buffer, skip uint, limit int) (dst *Buffer, err error)
- func DecompressLZW(src *Buffer, skip uint, limit int) (dst *Buffer, err error)
- func DecompressZLIB(src *Buffer, skip uint, limit int) (dst *Buffer, err error)
- func TakeBuffer() *Buffer
- func (b *Buffer) Allocate(n int)
- func (b *Buffer) Append(v []byte)
- func (b *Buffer) AppendByte(v byte)
- func (b *Buffer) AppendString(s string)
- func (b *Buffer) Cap() int
- func (b *Buffer) Extend(n int) []byte
- func (b *Buffer) Len() int
- func (b *Buffer) Read(v []byte) (n int, err error)
- func (b *Buffer) ReadDataFrom(r io.Reader, limit int) (int, error)
- func (b *Buffer) Reset()
- func (b *Buffer) Set(v []byte)
- func (b *Buffer) String() string
- func (b *Buffer) Write(v []byte) (n int, err error)
- func (b *Buffer) WriteDataTo(w io.Writer) error
- type Dispatcher
- type Flusher
- type ItemMPSC
- type Map
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) DeleteNoLock(key K)
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (m *Map[K, V]) Range(f func(k K, v V) bool)
- func (m *Map[K, V]) RangeLock(f func(k K, v V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- type QueueMPSC
- type RuntimeMetrics
Constants ¶
This section is empty.
Variables ¶
var (
DefaultBufferLength = 4096
)
Functions ¶
func EmitDeprecation ¶ added in v1.999.330
EmitDeprecation writes a deprecation warning at most once per name. If w is nil, os.Stderr is used.
func GenerateSelfSignedCert ¶
func GenerateSelfSignedCert(org string, hosts ...string) (tls.Certificate, error)
GenerateSelfSignedCert
func GetHostname ¶ added in v1.999.310
func GetHostname() string
func HashString64 ¶ added in v1.999.330
HashString64 returns a 64-bit FNV-1a hash of s. Used for distributing items across shards or queues. The algorithm is fixed so the same string always produces the same value across processes and across versions.
func PanicOrigin ¶ added in v1.999.330
func PanicOrigin() string
PanicOrigin returns "function[file:line]" a panic came from. Call it from the deferred recover.
Types ¶
type BiMap ¶ added in v1.999.310
type BiMap[A comparable, B comparable] struct { // contains filtered or unexported fields }
type Buffer ¶
type Buffer struct {
B []byte
// contains filtered or unexported fields
}
Buffer
func CompressGZIP ¶
CompressGZIP level: 0 - default, 1 - best speed, 2 - best size
func CompressLZW ¶
CompressLZW
func CompressZLIB ¶
CompressZLIB
func DecompressGZIP ¶
func DecompressZLIB ¶
func (*Buffer) ReadDataFrom ¶
ReadDataFrom
type Dispatcher ¶ added in v1.999.330
type Dispatcher[T any] struct { // contains filtered or unexported fields }
Dispatcher decouples producers from a single handler through a bounded MPSC queue and a worker that runs only while there is work: it is spawned on Push when idle and exits once the queue drains, so an idle dispatcher holds no goroutine (like a sleeping process). The queue grows lazily; nothing is pre-allocated. Push is non-blocking - a full queue drops the value and counts it. The handler is never called concurrently with itself.
func NewDispatcher ¶ added in v1.999.330
func NewDispatcher[T any](limit int, handle func(T)) *Dispatcher[T]
NewDispatcher builds a dispatcher whose worker passes every pushed value to handle. limit bounds the queue length; a non-positive limit uses defaultDispatcherLimit. The queue is always bounded, so a stalled handler makes Push drop rather than grow memory unbounded.
func (*Dispatcher[T]) Dropped ¶ added in v1.999.330
func (d *Dispatcher[T]) Dropped() uint64
Dropped returns how many values have been dropped so far because the queue was full.
func (*Dispatcher[T]) Push ¶ added in v1.999.330
func (d *Dispatcher[T]) Push(v T) bool
Push hands a value to the worker without blocking and reports whether it was queued. A full queue or a stopped dispatcher drops the value, counts it, and returns false, so a producer that cares can back off, retry or surface an error instead of losing it silently.
func (*Dispatcher[T]) Stop ¶ added in v1.999.330
func (d *Dispatcher[T]) Stop() []T
Stop prevents further work, waits for any in-flight handler to finish, and returns the values still queued so the caller can flush, inspect or discard them instead of losing them silently. After Stop returns the handler is guaranteed not to be running. Best-effort: a Push that raced Stop may or may not be included. Idempotent; a later Stop returns nil.
type Flusher ¶ added in v1.999.330
func NewFlusher ¶
type Map ¶
type Map[K comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
func (*Map[K, V]) DeleteNoLock ¶
func (m *Map[K, V]) DeleteNoLock(key K)
DeleteNoLock to be used within RangeLock method
func (*Map[K, V]) LoadAndDelete ¶
func (*Map[K, V]) LoadOrStore ¶
type QueueMPSC ¶
type QueueMPSC interface {
Push(value any) bool
Pop() (any, bool)
Item() ItemMPSC
// Len returns the number of items in the queue
Len() int64
// Size returns the limit for the queue. -1 - for unlimited
Size() int64
// Latency returns how long the oldest item has been in the queue (nanoseconds).
// Safe to call from any goroutine.
// Returns -1 if built without -tags=latency (measurement disabled).
// Returns 0 if the queue is empty.
Latency() int64
Lock() bool
Unlock() bool
}
func NewQueueLimitMPSC ¶
NewQueueLimitMPSC creates an MPSC queue bounded to the given length: Push returns false once the queue already holds limit items. A limit below 1 returns an unbounded queue (NewQueueMPSC).
func NewQueueMPSC ¶
func NewQueueMPSC() QueueMPSC
type RuntimeMetrics ¶ added in v1.999.330
type RuntimeMetrics struct {
// MemoryTotal is the total memory obtained from the OS, in bytes.
MemoryTotal uint64
// MemoryObjects is the memory occupied by live heap objects, in bytes.
MemoryObjects uint64
// MemoryLimit is the soft memory limit set via GOMEMLIMIT, in bytes.
// MaxInt64 means no limit is set.
MemoryLimit uint64
// HeapLive is the heap memory occupied as of the last garbage collection, in bytes.
HeapLive uint64
// HeapGoal is the heap size that triggers the next garbage collection, in bytes.
HeapGoal uint64
// Goroutines is the current number of goroutines.
Goroutines int64
// GCCycles is the cumulative number of completed garbage collection cycles.
GCCycles uint64
// HeapAllocObjects is the cumulative number of heap objects allocated.
HeapAllocObjects uint64
// HeapFreeObjects is the cumulative number of heap objects freed. The difference
// with HeapAllocObjects is the number of objects currently alive.
HeapFreeObjects uint64
// GCCPUFraction is the share of total CPU time spent in garbage collection.
GCCPUFraction float64
// CPUTimeGC is the cumulative CPU time spent in garbage collection, in seconds.
CPUTimeGC float64
// CPUTimeTotal is the cumulative CPU time available to the process, in seconds,
// as defined by GOMAXPROCS. Includes idle time.
CPUTimeTotal float64
}
RuntimeMetrics contains the runtime counters sampled through runtime/metrics. A metric unknown to the running Go version leaves its field zero.
func ReadRuntimeMetrics ¶ added in v1.999.330
func ReadRuntimeMetrics() RuntimeMetrics
ReadRuntimeMetrics samples the runtime counters. Unlike runtime.ReadMemStats it does not stop the world.