keycache

package
Version: v0.0.0-...-53bceb3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a single-tenant keycache it is sharded for 2 reasons: * more granular GC (eg. less latency perceived by caller) * mild space savings cause keys are 1 byte shorter We shard on the first byte of the metric key, which we assume is evenly distributed.

func NewCache

func NewCache(ref Ref) *Cache

NewCache creates a new cache

func (*Cache) Len

func (c *Cache) Len() int

Len returns the length of the cache

func (*Cache) Prune

func (c *Cache) Prune(now time.Time, staleThresh Duration) int

Prune makes sure all shards are pruned

func (*Cache) Touch

func (c *Cache) Touch(key schema.Key, t time.Time) bool

Touch marks the key as seen and returns whether it was seen before callers should assure that t >= ref and t-ref <= 42 hours

type Duration

type Duration uint8

Duration is a compact way to represent a duration bucketed in 10 minutely buckets. which allows us to cover a timeframe of 42 hours (just over a day and a half) because: 6 (10m periods per hour) *42 (hours) = 252 (10m periods)

func NewDuration

func NewDuration(ref Ref, t time.Time) Duration

NewDuration creates a new Duration representing the duration between Ref and t. callers responsibility that t >= ref and t-ref <= 42 hours

type KeyCache

type KeyCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

KeyCache tracks for all orgs, which keys have been seen, and when was the last time

func NewKeyCache

func NewKeyCache(staleThresh, pruneInterval time.Duration) *KeyCache

NewKeyCache creates a new KeyCache

func (*KeyCache) Len

func (k *KeyCache) Len() int

Len returns the size across all orgs

func (*KeyCache) Touch

func (k *KeyCache) Touch(key schema.MKey, t time.Time) bool

Touch marks the key as seen and returns whether it was seen before callers should assure that t >= ref and t-ref <= 42 hours

type Ref

type Ref uint32

Ref represents a unix timestamp bucketed in 10m buckets

func NewRef

func NewRef(t time.Time) Ref

type Shard

type Shard struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Shard tracks for each SubKey when it was last seen we know the last seen timestamp with ~10 minute precision because all SubKey's Duration's are relative to the ref

func NewShard

func NewShard(ref Ref) Shard

NewShard creates a new shard

func (*Shard) Len

func (s *Shard) Len() int

Len returns the length of the shard

func (*Shard) Prune

func (s *Shard) Prune(now time.Time, cutoff Duration) int

Prune removes stale entries from the shard. for this to work effectively, call this with a frequency > 10 min and < 42 hours

func (*Shard) Touch

func (s *Shard) Touch(key schema.Key, t time.Time) bool

Touch marks the key as seen and returns whether it was seen before callers should assure that t >= ref and t-ref <= 42 hours

type SubKey

type SubKey [15]byte

SubKey is the last 15 bytes of a 16 byte Key We can track Key-identified metrics with a SubKey because we shard by the first byte of the Key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL