Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ryanwinchester opened this issue May 10, 2024 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@ryanwinchester
Copy link
Owner

ryanwinchester commented May 10, 2024

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 ryanwinchester added help wanted Extra attention is needed question Further information is requested labels May 10, 2024
@ryanwinchester
Copy link
Owner Author

ryanwinchester commented May 10, 2024

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

NIF ideas to explore

@ryanwinchester ryanwinchester changed the title Would love to avoid using ETS. Ideas here (please share yours, too) Considering replacing ETS usage. Ideas here (please share yours, too) May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant