[erlang-questions] dialyzer: possible race condition with insert after lookup
Bob Ippolito
bob@REDACTED
Sun Oct 23 22:16:20 CEST 2011
I can't think of any way to do that algorithm correctly without
serialization of some kind. It's not actually an average, it's an
exponentially weighted moving average. You may want to investigate
using an application designed to collect metrics like this, such as
https://github.com/boundary/folsom -- I don't have any operational
experience with this particular app, but it's based on good ideas.
On Sun, Oct 23, 2011 at 12:19 PM, Joel Reymont <joelr1@REDACTED> wrote:
> What about this?
>
> _ = case ets:lookup(stats, Key1) of
> [{Key1, TS, latency, OldDelta}] ->
> %% have timings, average
> ets:insert(stats, [{Key1, TS, latency, (OldDelta + Delta) / 2}]);
> _ ->
> %% first timing, store
> ets:insert(stats, [{Key1, now(), latency, Delta}])
> end;
>
> On Oct 23, 2011, at 8:00 PM, Ulf Wiger wrote:
>
>>
>> This might please Dialyzer (I haven't tried):
>>
>> bump(Key, Value) ->
>> try ets:update_counter(stats, Key, {4, Value})
>> catch
>> error:_ ->
>> ets:insert_new(stats, {Key, now(), count, 0}),
>> ets:update_counter(stats, Key, {4, Value})
>> end.
>
> --------------------------------------------------------------------------
> - for hire: mac osx device driver ninja, kernel extensions and usb drivers
> ---------------------+------------+---------------------------------------
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> ---------------------+------------+---------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list