[erlang-questions] erlang:now() vs os:timestamp()

Fred Hebert mononcqc@REDACTED
Wed Apr 3 18:41:02 CEST 2013


Many things are missing in the benchmark, one of which is concurrency
and parallelism.

The calls you make are purely sequential, and you'll have pretty much no
lock contention on there.

now() is a monotonic function that always increases and thus requires a
global lock to read. It's generally very fast, but calling it hundreds
of times per second over thousands of processes is going to be worse
than calling os:timestamp() assuming your system doesn't add such a lock
to the os:timestamp() call.

I'd have to agree with the advice -- in practice, I tend to avoid using
now() and use os:timestamp(), unless I know I want my time to be
monotonic (and unique, albeit predictable).

Regards,
Fred.

On 04/03, Manuel A. Rubio "Bombadil" wrote:
> Hi,
> 
> I saw a keynote[1] from Rick Reed (WhatsApp) and he said: "Prefer
> os:timestamp to erlang:now"... I did a benchmark to test it[2], and
> get the following results:
> 
> os:timestamp =  1.44  1.38  1.38
> erlang:now   =  1.01  1.00  1.00
> 
> I know that he says "prefer" and not "better"... but the benchmark
> says that he should be say the opposite :-P
> 
> What do you think?
> 
> [1] http://www.erlang-factory.com/upload/presentations/558/efsf2012-whatsapp-scaling.pdf
> [2] https://gist.github.com/manuel-rubio/5302361
> 
> Regards.
> Manuel Rubio.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list