[erlang-questions] ets:update_counter/3 optimal settings
Tony Rogvall
tony@REDACTED
Fri Jun 9 12:33:31 CEST 2017
> 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 --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170609/0eaa0bc8/attachment.bin>
More information about the erlang-questions
mailing list