[erlang-questions] ets:update_counter/3 optimal settings
Frank Muller
frank.muller.erl@REDACTED
Fri Jun 9 14:03:54 CEST 2017
That's what I've implemented at the first place Tony.
But I like Alex's idea too.
/Frank
Le ven. 9 juin 2017 à 12:33, Tony Rogvall <tony@REDACTED> a écrit :
>
> > On 9 jun 2017, at 08:08, Alex S. <alex0player@REDACTED> wrote:
> >
> > Sounds right to me, with the caveat that read + reset to zero can lose
> some data if you are preempted between those two calls. My usual approach
> is read and decrement by -N, where N is the value I just read.
>
> When counter is none negative this can be done atomically like:
>
> hd(ets:update_counter(Tab, Key, [{Pos,0},{Pos,0,0,0}])).
>
> /Tony
>
> >> 9 июня 2017 г., в 8:44, Frank Muller <frank.muller.erl@REDACTED>
> написал(а):
> >>
> >> Hi Everyone,
> >>
> >> I've some troubles to understand the optimal settings for this little
> simple problem:
> >>
> >> Two Erlang processes A and B.
> >>
> >> 1. Process A randomly increments a counter during its lifetime using
> "ets:update_counter/3"
> >>
> >> 2. Process B reads the counter every X seconds and reset it to 0.
> >>
> >> I decided to use these options when creating the table:
> >>
> >> {write_concurrency, true}, %% A and B
> >> {read_concurrency, false} %% only B
> >>
> >> Are these settings correct and more importantly "optimal" (please
> elaborate your answer)?
> >>
> >> /Frank
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170609/ce4fea75/attachment.htm>
More information about the erlang-questions
mailing list