Documentation
¶
Index ¶
- type HashFn
- type HotRing
- func (h *HotRing) Close()
- func (h *HotRing) EnableDecay(interval time.Duration, shift uint32)
- func (h *HotRing) EnableNodeSampling(cap uint64, sampleBits uint8)
- func (h *HotRing) EnableSlidingWindow(slots int, slotDuration time.Duration)
- func (h *HotRing) Frequency(key string) int32
- func (h *HotRing) KeysAbove(threshold int32) []Item
- func (h *HotRing) Remove(key string)
- func (h *HotRing) SetObserver(obs Observer)
- func (h *HotRing) SnapshotKeysAbove(threshold int32) Snapshot
- func (h *HotRing) SnapshotTopN(n int) Snapshot
- func (h *HotRing) Stats() Stats
- func (h *HotRing) TopN(n int) []Item
- func (h *HotRing) Touch(key string) int32
- func (h *HotRing) TouchAndClamp(key string, limit int32) (count int32, limited bool)
- type Item
- type Node
- func (n *Node) CompareAndSwapNext(old, next *Node) bool
- func (n *Node) Equal(c *Node) bool
- func (n *Node) GetCounter() int32
- func (n *Node) Increment() int32
- func (n *Node) Less(c *Node) bool
- func (n *Node) Next() *Node
- func (n *Node) ResetCounter()
- func (n *Node) ResetCounterWithWindow(slots int, slotID int64)
- func (n *Node) SetNext(next *Node)
- type Observer
- type RotatingHotRing
- func (r *RotatingHotRing) ActiveStats() Stats
- func (r *RotatingHotRing) Close()
- func (r *RotatingHotRing) EnableDecay(interval time.Duration, shift uint32)
- func (r *RotatingHotRing) EnableNodeSampling(cap uint64, sampleBits uint8)
- func (r *RotatingHotRing) EnableRotation(interval time.Duration)
- func (r *RotatingHotRing) EnableSlidingWindow(slots int, slotDuration time.Duration)
- func (r *RotatingHotRing) Frequency(key string) int32
- func (r *RotatingHotRing) KeysAbove(threshold int32) []Item
- func (r *RotatingHotRing) KeysAboveMax(threshold int32) []Item
- func (r *RotatingHotRing) Remove(key string)
- func (r *RotatingHotRing) Rotate()
- func (r *RotatingHotRing) RotationStats() RotationStats
- func (r *RotatingHotRing) SetObserver(obs Observer)
- func (r *RotatingHotRing) SnapshotKeysAbove(threshold int32) Snapshot
- func (r *RotatingHotRing) SnapshotKeysAboveMax(threshold int32) Snapshot
- func (r *RotatingHotRing) SnapshotTopN(n int) Snapshot
- func (r *RotatingHotRing) SnapshotTopNMax(n int) Snapshot
- func (r *RotatingHotRing) Stats() Stats
- func (r *RotatingHotRing) TopN(n int) []Item
- func (r *RotatingHotRing) TopNMax(n int) []Item
- func (r *RotatingHotRing) Touch(key string) int32
- func (r *RotatingHotRing) TouchAndClamp(key string, limit int32) (int32, bool)
- func (r *RotatingHotRing) WarmStats() Stats
- type RotationStats
- type Snapshot
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HotRing ¶
type HotRing struct {
// contains filtered or unexported fields
}
HotRing keeps track of frequently accessed keys using lock-free bucketed lists.
func NewHotRing ¶
NewHotRing builds a ring with 2^bits buckets. When fn is nil a fast xxhash-based hash is used.
func (*HotRing) Close ¶
func (h *HotRing) Close()
Close releases background resources attached to the ring.
func (*HotRing) EnableDecay ¶
EnableDecay applies periodic right-shift decay to the raw counters. interval <= 0 or shift == 0 disables background decay.
func (*HotRing) EnableNodeSampling ¶ added in v0.4.0
EnableNodeSampling caps node growth and applies stable sampling once the cap is reached. cap <= 0 disables the cap. sampleBits controls the sampling rate (1/2^sampleBits). sampleBits == 0 means no sampling when the cap is exceeded (strict cap).
func (*HotRing) EnableSlidingWindow ¶
EnableSlidingWindow configures the ring to maintain a time-based sliding window. slots specifies how many buckets to retain, while slotDuration controls how long each bucket remains active. Passing non-positive values disables the window.
func (*HotRing) Frequency ¶
Frequency returns the current access counter for key without mutating state.
func (*HotRing) SetObserver ¶ added in v0.2.0
SetObserver registers an optional observer hook.
func (*HotRing) SnapshotKeysAbove ¶ added in v0.2.0
SnapshotKeysAbove captures a threshold snapshot with a timestamp.
func (*HotRing) SnapshotTopN ¶ added in v0.2.0
SnapshotTopN captures a Top-N snapshot with a timestamp.
func (*HotRing) Stats ¶ added in v0.2.0
Stats returns a lightweight view of ring configuration and counters.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) CompareAndSwapNext ¶
func (*Node) GetCounter ¶
func (*Node) ResetCounter ¶
func (n *Node) ResetCounter()
func (*Node) ResetCounterWithWindow ¶
type Observer ¶ added in v0.2.0
type Observer interface {
OnTouch(key string, count int32)
OnClamp(key string, limit int32, count int32)
OnDecay(shift uint32)
}
Observer receives optional notifications for observability hooks.
type RotatingHotRing ¶ added in v0.5.0
type RotatingHotRing struct {
// contains filtered or unexported fields
}
RotatingHotRing wraps HotRing with dual-ring time-based rotation. Rotation swaps in a fresh active ring and keeps the previous generation warm.
func NewRotatingHotRing ¶ added in v0.5.0
func NewRotatingHotRing(bits uint8, fn HashFn) *RotatingHotRing
NewRotatingHotRing builds a rotating ring with 2^bits buckets.
func (*RotatingHotRing) ActiveStats ¶ added in v0.5.0
func (r *RotatingHotRing) ActiveStats() Stats
ActiveStats returns stats for the active ring.
func (*RotatingHotRing) Close ¶ added in v0.5.0
func (r *RotatingHotRing) Close()
Close releases background resources attached to the rotating ring.
func (*RotatingHotRing) EnableDecay ¶ added in v0.5.0
func (r *RotatingHotRing) EnableDecay(interval time.Duration, shift uint32)
EnableDecay applies periodic right-shift decay to the raw counters.
func (*RotatingHotRing) EnableNodeSampling ¶ added in v0.5.0
func (r *RotatingHotRing) EnableNodeSampling(cap uint64, sampleBits uint8)
EnableNodeSampling caps node growth and applies stable sampling once the cap is reached.
func (*RotatingHotRing) EnableRotation ¶ added in v0.5.0
func (r *RotatingHotRing) EnableRotation(interval time.Duration)
EnableRotation starts or stops time-based rotation. interval <= 0 disables rotation.
func (*RotatingHotRing) EnableSlidingWindow ¶ added in v0.5.0
func (r *RotatingHotRing) EnableSlidingWindow(slots int, slotDuration time.Duration)
EnableSlidingWindow configures the ring to maintain a time-based sliding window.
func (*RotatingHotRing) Frequency ¶ added in v0.5.0
func (r *RotatingHotRing) Frequency(key string) int32
Frequency returns the current access counter for key without mutating state.
func (*RotatingHotRing) KeysAbove ¶ added in v0.5.0
func (r *RotatingHotRing) KeysAbove(threshold int32) []Item
KeysAbove returns all keys whose counters are at least threshold.
func (*RotatingHotRing) KeysAboveMax ¶ added in v0.5.0
func (r *RotatingHotRing) KeysAboveMax(threshold int32) []Item
KeysAboveMax returns all keys whose counters are at least threshold using max merge.
func (*RotatingHotRing) Remove ¶ added in v0.5.0
func (r *RotatingHotRing) Remove(key string)
Remove deletes a key from the active ring.
func (*RotatingHotRing) Rotate ¶ added in v0.5.0
func (r *RotatingHotRing) Rotate()
Rotate swaps in a fresh ring and releases background resources of the old ring.
func (*RotatingHotRing) RotationStats ¶ added in v0.5.0
func (r *RotatingHotRing) RotationStats() RotationStats
RotationStats returns rotation counters and configuration.
func (*RotatingHotRing) SetObserver ¶ added in v0.5.0
func (r *RotatingHotRing) SetObserver(obs Observer)
SetObserver registers an optional observer hook.
func (*RotatingHotRing) SnapshotKeysAbove ¶ added in v0.5.0
func (r *RotatingHotRing) SnapshotKeysAbove(threshold int32) Snapshot
SnapshotKeysAbove captures a threshold snapshot with a timestamp.
func (*RotatingHotRing) SnapshotKeysAboveMax ¶ added in v0.5.0
func (r *RotatingHotRing) SnapshotKeysAboveMax(threshold int32) Snapshot
SnapshotKeysAboveMax captures a threshold snapshot using max merge semantics.
func (*RotatingHotRing) SnapshotTopN ¶ added in v0.5.0
func (r *RotatingHotRing) SnapshotTopN(n int) Snapshot
SnapshotTopN captures a Top-N snapshot with a timestamp.
func (*RotatingHotRing) SnapshotTopNMax ¶ added in v0.5.0
func (r *RotatingHotRing) SnapshotTopNMax(n int) Snapshot
SnapshotTopNMax captures a Top-N snapshot using max merge semantics.
func (*RotatingHotRing) Stats ¶ added in v0.5.0
func (r *RotatingHotRing) Stats() Stats
Stats returns a lightweight view of ring configuration and counters.
func (*RotatingHotRing) TopN ¶ added in v0.5.0
func (r *RotatingHotRing) TopN(n int) []Item
TopN returns at most n hot keys ordered by access count (descending).
func (*RotatingHotRing) TopNMax ¶ added in v0.5.0
func (r *RotatingHotRing) TopNMax(n int) []Item
TopNMax returns at most n hot keys ordered by access count (descending) using max merge.
func (*RotatingHotRing) Touch ¶ added in v0.5.0
func (r *RotatingHotRing) Touch(key string) int32
Touch records a key access and returns the updated counter.
func (*RotatingHotRing) TouchAndClamp ¶ added in v0.5.0
func (r *RotatingHotRing) TouchAndClamp(key string, limit int32) (int32, bool)
TouchAndClamp increments the counter if below the provided limit.
func (*RotatingHotRing) WarmStats ¶ added in v0.5.0
func (r *RotatingHotRing) WarmStats() Stats
WarmStats returns stats for the warm ring.
type RotationStats ¶ added in v0.5.0
type RotationStats struct {
Interval time.Duration `json:"interval"`
Rotations uint64 `json:"rotations"`
LastRotateUnix int64 `json:"last_rotate_unix"`
}
RotationStats reports rotation activity for a RotatingHotRing.
type Stats ¶ added in v0.2.0
type Stats struct {
Buckets int `json:"buckets"`
Nodes uint64 `json:"nodes"`
LoadFactor float64 `json:"load_factor"`
WindowSlots int `json:"window_slots"`
WindowSlotDuration time.Duration `json:"window_slot_duration"`
DecayInterval time.Duration `json:"decay_interval"`
DecayShift uint32 `json:"decay_shift"`
NodeCap uint64 `json:"node_cap"`
SampleMask uint32 `json:"sample_mask"`
Touches uint64 `json:"touches"`
Inserts uint64 `json:"inserts"`
Removes uint64 `json:"removes"`
Clamps uint64 `json:"clamps"`
SampleDrops uint64 `json:"sample_drops"`
DecayRuns uint64 `json:"decay_runs"`
LastDecayUnix int64 `json:"last_decay_unix"`
}
Stats exposes lightweight observability data for a HotRing instance.