CounterEx.Backend.ETS (CounterEx v0.2.0)

View Source

ETS-based backend for CounterEx.

This backend uses Erlang Term Storage (ETS) for counter storage, providing:

  • Dynamic counters: Create unlimited counters on-demand
  • High concurrency: Optimized for both reads and writes
  • Flexible keys: Support for atom and binary keys
  • Per-namespace tables: Each namespace gets its own ETS table

Characteristics

  • Performance: ~3-4M ops/sec
  • Memory: Grows dynamically with number of counters
  • Limitations: None on counter count or value range

Configuration

Options:

  • :base_table_name - Base name for ETS tables (default: :counter_ex_ets)

Example

{:ok, state} = CounterEx.Backend.ETS.init(base_table_name: :my_counters)
{:ok, 1} = CounterEx.Backend.ETS.inc(state, :default, :my_counter, 1, 0)
{:ok, 1} = CounterEx.Backend.ETS.get(state, :default, :my_counter)

Summary

Types

t()

@type t() :: %CounterEx.Backend.ETS{base_name: atom(), registry: :ets.tid()}