Skip Menu |
Report information
Id: 128878
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: alex.jakimenko [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: Supply.interval is drifting
Code:
Supply.interval(1).tap: {say (now - BEGIN now) % 1}; sleep ∞

Result:
0.0304637
0.03055483
0.0314534
0.0325942
0.03372027
0.0340993
0.0352113
0.036300
0.0373585
0.03846543
0.0395657
0.0406380
0.04169298
0.0428189
0.0439086



In this case it is about 1ms per second, which is probably very bad. Is there any reason for it to do so?
As a user, I expect it not to drift.
Download (untitled) / with headers
text/plain 986b
On Tue Aug 09 14:36:10 2016, alex.jakimenko@gmail.com wrote: Show quoted text
> Code: > Supply.interval(1).tap: {say (now - BEGIN now) % 1}; sleep ∞ > > Result: > 0.0304637 > 0.03055483 > 0.0314534 > 0.0325942 > 0.03372027 > 0.0340993 > 0.0352113 > 0.036300 > 0.0373585 > 0.03846543 > 0.0395657 > 0.0406380 > 0.04169298 > 0.0428189 > 0.0439086 > … > > > In this case it is about 1ms per second, which is probably very bad. > Is there > any reason for it to do so? > As a user, I expect it not to drift.
Are you sure it's not just an artifact of your measurement method? I'm not even sure what it's measuring. Compare these: perl6 -e 'for ^Inf { sleep .1; say (now - BEGIN now) % 1 }' Shows your "drift" that wobbles between 0.1 and 0.9 seconds. perl6 -e 'for ^Inf { sleep .1; say now - BEGIN now }' Shows all the values incrementing by .1 seconds, no drifts, as is proper. The occasional extra .01 seconds is expected, as we sleep for 'at least' .1 seconds and can't be super exact.
Date: Fri, 12 Aug 2016 07:14:07 +0300
From: Aleks-Daniel Jakimenko-Aleksejev <alex.jakimenko [...] gmail.com>
To: perl6-bugs-followup [...] perl.org
Subject: Re: [perl #128878] Supply.interval is drifting
Download (untitled) / with headers
text/plain 1.7k
You can do it without % 1, sure. It is there to make it easier to see the drift with your eyes, but you can see it without it.

> The occasional extra .01 seconds is expected, as we sleep for 'at least' .1 seconds and can't be super exact.

Sure, but there is no 「sleep」 in Supply.interval(1) example (except for the one that sleeps forever).

My point is that Supply.interval() drifts. Yes, by a small amount of 1 ms each tick, but drifts nonetheless.

I am not sure what TimToady meant here: http://irclog.perlgeek.de/perl6/2016-08-09#i_12994683 but it sounds like there must be some Supply feature that does not drift. If it is not Supply.interval(), then what is it?


On Fri, Aug 12, 2016 at 6:11 AM, Zoffix Znet via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
On Tue Aug 09 14:36:10 2016, alex.jakimenko@gmail.com wrote:
> Code:
> Supply.interval(1).tap: {say (now - BEGIN now) % 1}; sleep ∞
>
> Result:
> 0.0304637
> 0.03055483
> 0.0314534
> 0.0325942
> 0.03372027
> 0.0340993
> 0.0352113
> 0.036300
> 0.0373585
> 0.03846543
> 0.0395657
> 0.0406380
> 0.04169298
> 0.0428189
> 0.0439086
> …
>
>
> In this case it is about 1ms per second, which is probably very bad.
> Is there
> any reason for it to do so?
> As a user, I expect it not to drift.

Are you sure it's not just an artifact of your measurement method? I'm not even sure what it's measuring.

Compare these:

    perl6 -e 'for ^Inf { sleep .1; say (now - BEGIN now) % 1 }'

Shows your "drift" that wobbles between 0.1 and 0.9 seconds.

    perl6 -e 'for ^Inf { sleep .1; say now - BEGIN now }'

Shows all the values incrementing by .1 seconds, no drifts, as is proper. The occasional extra .01 seconds is expected, as we sleep for 'at least' .1 seconds and can't be super exact.

Download (untitled) / with headers
text/plain 586b
On Thu Aug 11 21:14:41 2016, alex.jakimenko@gmail.com wrote: Show quoted text
> Sure, but there is no 「sleep」 in Supply.interval(1) example [...] > My point is that Supply.interval() drifts. Yes, by a small amount of 1 > ms > each tick, but drifts nonetheless.
I'm not familiar with the internals, but I'd suspect that drift in .interval() is for the same reasons there's drift in sleep(). It emits in intervals of at least X seconds, which I'd expect it to do, rather than to keep true to some arbitrary starting point, frequently emitting in smaller-than-X-seconds intervals just to compensate.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org