uuidv7
uuidv7 copied to clipboard
Considering replacing ETS usage. Ideas here (please share yours, too)
Share ideas on how to replace the ETS table.
Requirements:
- We need to be able to atomically increment a randomly-seeded 18-bit counter.
- Reset+reseed every time we have a different millisecond timestamp.
- Reset it to next millisecond at rollover.
- Not have it grow infinitely.
Arguments:
- current millisecond timestamp and
- 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.
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?]
We don't use ETS anymore