Hi, is anyone using the new-ish erlang counters, please?
Could you please show some examples? I was able to create new counter with {:atomics, counter_ref} = :counters.new(1, []) but then :counters.info(counter_ref)is throwing (ArgumentError) – I guess I’m just wrongly “translating” from Erlang…
Also, what are good and bad use cases for these counters, please?
any hints when to use these, and on the contrary, when not?
I was thinking of using Redis for concurrent counter recently, but was looking also for ETS alternatives, when I found these counters. I assume that unlike in Redis, these are not persisted in any way by default?
Yes, these aren’t persisted and aren’t distributed in any way.
It is handy in situations like metrics where you just want to gather counts as cheaply as possible. Other use cases are logging facility where you want some kind of overload protection, that will cheaply count incoming requests and then react respectively in case of overload. You can also use them for implementing circuit breakers or any other situation where you need to count things cross process as cheaply as possible.