RpcLoadBalancer.LoadBalancer.CounterCache (rpc_load_balancer v0.3.4)

Copy Markdown View Source

Shared atomic counters for slot-based round-robin and per-node connection tracking across all load balancers.

Summary

Functions

adapter_options()

cache_adapter()

cache_name()

child_spec(_)

counter_ref()

@spec counter_ref() :: :counters.counters_ref()

Returns the underlying :counters reference for the shared counter cache.

Hot-path callers cache this once per selection (or per process) and use :counters.get/2 / :counters.add/3 directly instead of paying the :telemetry.span/3 overhead of Cache.get/1 per read.

decrement(key, step \\ 1)

Atomically decrements the counter for the given key by step (default 1).

decrement_node(load_balancer_name, node)

@spec decrement_node(atom(), node()) :: :ok

delete(key)

erase_node_counter(load_balancer_name, node)

@spec erase_node_counter(atom(), node()) :: :ok

get(key)

get_and_increment(index)

@spec get_and_increment(non_neg_integer()) :: non_neg_integer()

get_node_count(load_balancer_name, node)

@spec get_node_count(atom(), node()) :: non_neg_integer()

Read a node's connection count without telemetry overhead.

Goes straight to :counters.get/2, skipping the :telemetry.span/3-wrapped Cache.get/1. Returns 0 for nodes that haven't been registered yet so callers can treat a missing entry as the natural "lowest" candidate.

get_or_create(key, fnc)

increment(key, step \\ 1)

Atomically increments the counter for the given key by step (default 1).

increment_node(load_balancer_name, node)

@spec increment_node(atom(), node()) :: :ok

put(key, ttl \\ nil, value)

register(load_balancer_name, slot_id)

@spec register(atom(), pos_integer()) :: non_neg_integer()

register_node(load_balancer_name, node)

@spec register_node(atom(), node()) :: non_neg_integer()

reset_counter(index)

@spec reset_counter(non_neg_integer()) :: :ok