Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was erlang:now() specced such that it may skew the time of a node?

the erlang documentation says:

erlang:now()
[...] It is also guaranteed that subsequent calls to this BIF returns continuously increasing values. Hence, the return value from now() can be used to generate unique time-stamps, and if it is called in a tight loop on a fast machine the time of the node can become skewed. [...]

I find this a little strange (especially considering that the granularity is microsecond). Why was it specced this way?

like image 469
Enno Shioji Avatar asked Mar 06 '11 12:03

Enno Shioji


People also ask

How does the Erlang runtime system work?

The runtime system works towards aligning the two system times. Depending on the time warp mode used, this can be achieved by letting Erlang system time perform a time warp. A monotonically increasing time provided by the Erlang runtime system. Erlang monotonic time increases since some unspecified point in time.

Why does Erlang monotonic time stop?

If OS system time leaps backwards, Erlang monotonic time stops briefly, but it does not freeze for extended periods of time. This as the time offset is changed to align Erlang system time with OS system time. To use this mode, ensure that all Erlang code that will execute on the runtime system is time warp safe.

What happens when Erlang time does a Time Warp backwards?

When Erlang system time does a time warp backwards, the values returned from erlang:now/0 freeze (if you disregard the microsecond increments made because of the actual call) until OS system time reaches the point of the last value returned by erlang:now/0. This freeze can continue for a long time.

Is Erlang now/0 backward compatible?

To be backward compatible, erlang:now/0 remains "as is", but you are strongly discouraged from using it. Many use cases of erlang:now/0 prevents you from using the new multi-time warp mode, which is an important part of this new time functionality improvement.


1 Answers

Because it can then be used to uniquely generate timestamp numbers. The os module has a variant which does not do that.

like image 55
I GIVE CRAP ANSWERS Avatar answered Sep 20 '22 08:09

I GIVE CRAP ANSWERS