sleep for a few microsconds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

sleep for a few microsconds

atul goyal
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 :

1. Used linux 'nanosleep' from a 'C' NIF ::
Gives 50-90% error between 1-500 microsec ... and even at 1500 microsec it gives 10-20% error . I tried giving high priority to Beam process .. same results

2.Busywait in Erlang function  ::
Isnt practical to waste CPU time when serving a large number of users ...Also it is only good for about 90% of the time but rest of the time gives 50-200% error ...

thanks a lot
Atul

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

Max Lapshin-2
Afraid that it is not possible.

Perhaps the only way is to have a thread that will execute your commands with a nanosleep precision.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

Vance Shipley
In reply to this post by atul goyal
On Thu, Nov 16, 2017 at 12:57 PM, Atul Goyal <[hidden email]> wrote:
> I was wondering if there is a way to sleep for few u'sec in erlang .

Do the opposite?

1> F = fun(F, T1, T2) when T1 < T2 ->
1>           F(F, erlang:system_time(milli_seconds), T2);
1>        (_, _, _) ->
1>           ok
1> end,
1> T = erlang:system_time(milli_seconds),
1> F(F, T, T + 3).
ok


--
     -Vance
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

atul goyal
In reply to this post by Max Lapshin-2
do u mean using new OS thread which might be spawned from say a linked in driver ?

Thanks

On Thu, Nov 16, 2017 at 1:55 PM, Max Lapshin <[hidden email]> wrote:
Afraid that it is not possible.

Perhaps the only way is to have a thread that will execute your commands with a nanosleep precision.



--
atul

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

atul goyal
In reply to this post by Vance Shipley
hi Vance

Thanks but already  tried that :)


On Thu, Nov 16, 2017 at 2:06 PM, Vance Shipley <[hidden email]> wrote:
On Thu, Nov 16, 2017 at 12:57 PM, Atul Goyal <[hidden email]> wrote:
> I was wondering if there is a way to sleep for few u'sec in erlang .

Do the opposite?

1> F = fun(F, T1, T2) when T1 < T2 ->
1>           F(F, erlang:system_time(milli_seconds), T2);
1>        (_, _, _) ->
1>           ok
1> end,
1> T = erlang:system_time(milli_seconds),
1> F(F, T, T + 3).
ok


--
     -Vance



--
atul

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

Max Lapshin-2
Yes.

I mean separate thread, spawned from driver or nif that will consume your jobs with timings and do required sleep.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

Sergej Jurečko
In reply to this post by atul goyal
Have you tried nanosleep accuracy in a simple C program by itself? Especially on a non-idle machine. Also I hope you’re not running or planning on running anything like that in a VM.

Regards,
Sergej

> On 16 Nov 2017, at 08:27, Atul Goyal <[hidden email]> 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 :
>
> 1. Used linux 'nanosleep' from a 'C' NIF ::
> Gives 50-90% error between 1-500 microsec ... and even at 1500 microsec it gives 10-20% error . I tried giving high priority to Beam process .. same results
>
> 2.Busywait in Erlang function  ::
> Isnt practical to waste CPU time when serving a large number of users ...Also it is only good for about 90% of the time but rest of the time gives 50-200% error ...
>
> thanks a lot
> Atul
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

atul goyal

Ya ... i checked nanosleep accuracy in pure c first .. with rt priority too ... it was quite accurate..
And i am using a physical machine .
Thanks


On 17-Nov-2017 01:14, "Sergej Jurečko" <[hidden email]> wrote:
Have you tried nanosleep accuracy in a simple C program by itself? Especially on a non-idle machine. Also I hope you’re not running or planning on running anything like that in a VM.

Regards,
Sergej

> On 16 Nov 2017, at 08:27, Atul Goyal <[hidden email]> 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 :
>
> 1. Used linux 'nanosleep' from a 'C' NIF ::
> Gives 50-90% error between 1-500 microsec ... and even at 1500 microsec it gives 10-20% error . I tried giving high priority to Beam process .. same results
>
> 2.Busywait in Erlang function  ::
> Isnt practical to waste CPU time when serving a large number of users ...Also it is only good for about 90% of the time but rest of the time gives 50-200% error ...
>
> thanks a lot
> Atul
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

PAILLEAU Eric
Hi,

Erlang is soft real time, not hard realtime.
I think it is hard to achieve an "exact" nanosleep in particular on
multiCPU .

Did you tried using a custom recursing function where argument is
(somewhat) linear to execution time ?

regards


Le 16/11/2017 à 21:27, Atul Goyal a écrit :

> Ya ... i checked nanosleep accuracy in pure c first .. with rt priority
> too ... it was quite accurate..
> And i am using a physical machine .
> Thanks
>
>
> On 17-Nov-2017 01:14, "Sergej Jurečko" <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Have you tried nanosleep accuracy in a simple C program by itself?
>     Especially on a non-idle machine. Also I hope you’re not running or
>     planning on running anything like that in a VM.
>
>     Regards,
>     Sergej
>
>      > On 16 Nov 2017, at 08:27, Atul Goyal <[hidden email]
>     <mailto:[hidden email]>> 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 :
>      >
>      > 1. Used linux 'nanosleep' from a 'C' NIF ::
>      > Gives 50-90% error between 1-500 microsec ... and even at 1500
>     microsec it gives 10-20% error . I tried giving high priority to
>     Beam process .. same results
>      >
>      > 2.Busywait in Erlang function  ::
>      > Isnt practical to waste CPU time when serving a large number of
>     users ...Also it is only good for about 90% of the time but rest of
>     the time gives 50-200% error ...
>      >
>      > thanks a lot
>      > Atul
>      > _______________________________________________
>      > erlang-questions mailing list
>      > [hidden email] <mailto:[hidden email]>
>      > http://erlang.org/mailman/listinfo/erlang-questions
>     <http://erlang.org/mailman/listinfo/erlang-questions>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: sleep for a few microsconds

Jesper Louis Andersen-2
In reply to this post by atul goyal
On Thu, Nov 16, 2017 at 8:28 AM Atul Goyal <[hidden email]> 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. 

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions