[erlang-patches] [patch] fix excessive CPU consumption of timer_server

Aliaksey Kandratsenka alkondratenko@REDACTED
Thu Apr 11 19:32:04 CEST 2013


On Thu, Apr 11, 2013 at 8:12 AM, Björn Gustavsson <bgustavsson@REDACTED>wrote:

> On Tue, Apr 9, 2013 at 9:27 PM, Aliaksey Kandratsenka <
> alkondratenko@REDACTED> wrote:
>
>>
>> I've updated patch to use erlang:now instead of os:timestamp.
>>
>>
> Thanks! We have now reviewed the code and have
> found a minor potential issue.
>
> The thing is that if two timers are set to the same
> value, they are now guaranteed to expire in the same
> order that they were set. That is because erlang:now/0
> returns unique values. (See timer_timeout/1.)
>
> With your patch, timers set to the same timeout
> within the same millisecond will have identical
> target times. Since the key in the ets table
> (at least for one shot timers) is tuple with the
> second element a reference, the ordering of the
> refs will determine which key that erts:first/1 will
> return if the target times are identical.
>
> In the current implementation, it *happens* to
> be true that if only and if Ref1 < Ref2, then
> Ref1 was created before Ref2. But that property
> is not guaranteed by the language definition and it
> may be changed in a future release (e.g. to reduce
> contention of the lock that is taken when refs are
> created).
>
> Therefore, I suggest fixing the bug by keeping
> the original system_time/0 function and
> round up when dividing by 1000. (The easiest
> way to round up is to add 999 before dividing
> by 1000.)
>

That makes sense. Thanks for thorough review.

I've updated patch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130411/48741769/attachment.htm>


More information about the erlang-patches mailing list