[erlang-questions] sleep for a few microsconds

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sat Nov 18 15:41:18 CET 2017


On Thu, Nov 16, 2017 at 8:28 AM Atul Goyal <atulindore2@REDACTED> wrote:

> hi
>
> I was wondering if there is a way to sleep for few u'sec in erlang . We
> are working on  Linux. And we have tried following solutions :
>
>
If you require microsecond precision sleeps, then chances are you won't be
happy with either Erlang (or for that matter, Go). The problem is that in a
highly concurrent system, with soft-realtime constraints, you can't be
guaranteed a wakeup within a window every time. If you have 100000
processes on the run-queue, you will have to wait, one way or the other.

Mind you, a hard realtime system wouldn't even allow you to start 100000
processes. It would start rejecting your spawns as soon as it can't make
the guarantee.

What Erlang systems *do* tend to do well in this regard is that the
performance degrades linearly as the system becomes overloaded. That is, it
is considerably harder to monopolize the CPU resources in an Erlang system
compared to other systems (Haskell and Go fares well here too, but they
require more scheduling points at the moment to be injected by the
programmer).

This is also the reason the precision is in milliseconds: it is far more
likely that the Erlang system can meet the ms-window than the us or
ns-windows. However, even that is no guarantee: a highly loaded system will
fire timers late.

The best way to cope with the lack of precision is to have a low-level
precise system which you periodically feed from the Erlang world. Much like
how you wake up and feed the small soundcard buffer once in a while to keep
on playing. This is also how you can handle a mobile phone cell system:
handle the low-level latency stuff elsewhere and use the Erlang system for
orchestration.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171118/6ff20c69/attachment.htm>


More information about the erlang-questions mailing list