uuidv7 icon indicating copy to clipboard operation
uuidv7 copied to clipboard

Considering replacing ETS usage. Ideas here (please share yours, too)

Open ryanwinchester opened this issue 1 year ago • 1 comments

Share ideas on how to replace the ETS table.

Requirements:

  1. We need to be able to atomically increment a randomly-seeded 18-bit counter.
  2. Reset+reseed every time we have a different millisecond timestamp.
  3. Reset it to next millisecond at rollover.
  4. Not have it grow infinitely.

Arguments:

  1. current millisecond timestamp and
  2. a 17-bit random integer for a seed.

Current implementation:

We have an ETS table that has timestamps as the key, and updates a counter.

  defp update_counter(timestamp, seed) do
    :ets.update_counter(__MODULE__, timestamp, 1, {timestamp, seed})
  end

Once it hits the 18-bit threshold we then increment the millisecond timestamp key to avoid rollover.

We also delete old keys on a recurring interval.

ryanwinchester avatar May 10 '24 11:05 ryanwinchester

Current idea I want to explore is to use a NIF.

NIF ideas to explore

  • [ ] consider https://github.com/xacrimon/dashmap
  • [ ] [TODO: add more here. any other ideas?]

ryanwinchester avatar May 10 '24 11:05 ryanwinchester

We don't use ETS anymore

ryanwinchester avatar Feb 27 '25 02:02 ryanwinchester