Re: sleep 3600 vs task scheduler

2020-04-08 Thread ToddAndMargo via perl6-users

On 2020-04-07 20:44, ToddAndMargo via perl6-users wrote:

On 2020-04-07 20:39, Paul Procacci wrote:

What happens when you try it?
What impact do you observe?

My guess is the impact is exactly the time it takes for your cpu to 
perform the initial context switch for the syscall, and then another 
when waking up.


Hi Paul,

I opened the resource monitor and watched the CPU load:

raku -e "say 'start sleep 10'; sleep 10; say 'stop sleep;'"
start sleep 10
stop sleep;

Nothing.  Sleep must be recovering using a system interrupt.
Yippee!

-T



This is what I was afraid of.  The old fashioned batch
programming wait 10 seconds:

>ping -n 10 -i 10 8.8.8.8


Re: sleep 3600 vs task scheduler

2020-04-07 Thread ToddAndMargo via perl6-users

On 2020-04-07 20:39, Paul Procacci wrote:

What happens when you try it?
What impact do you observe?

My guess is the impact is exactly the time it takes for your cpu to 
perform the initial context switch for the syscall, and then another 
when waking up.


Hi Paul,

I opened the resource monitor and watched the CPU load:

raku -e "say 'start sleep 10'; sleep 10; say 'stop sleep;'"
start sleep 10
stop sleep;

Nothing.  Sleep must be recovering using a system interrupt.
Yippee!

-T


Re: sleep 3600 vs task scheduler

2020-04-07 Thread Paul Procacci
What happens when you try it?
What impact do you observe?

My guess is the impact is exactly the time it takes for your cpu to perform
the initial context switch for the syscall, and then another when waking up.

On Tue, Apr 7, 2020 at 10:28 PM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Tue, Apr 7, 2020 at 6:02 AM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> Windows 7/10
> >>
> >> Another piece of the puzzle.
> >>
> >> I want to loop Raku program once an hour.
> >>
> >> Is it better use `sleep 3600` or let the program
> >> die and restart every hour from the Task Scheduler.
> >> By better, I mean less of a CPU footprint.
> >>
> >> `sleep` would allow the user to cancel the program
> >> and not have it come back.
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-04-07 19:22, Brad Gilbert wrote:
> > Run code once an hour:
> >
> >  react whenever Supply.interval(60 * 60) {
> >  say "it's been an hour"
> >  }
> >
> > Right now that gets about 0.01 seconds slower every time the interval
> runs.
> > (At least on my computer.)
> > So it will get 1 second later every 4 days.
> >
> >
> > Or if you want more precise control, you could do something like:
> >
> > Here is an example that is more accurate, and happens at the top of the
> > hour:
> >
> >  sub every-hour ( --> Supply:D ) {
> >  supply {
> >  sub add-next ( $hour --> Nil ) {
> >  whenever Promise.at( $hour.Instant ) {
> >  emit $hour;
> >  add-next( $hour.later(:1hour) );
> >  }
> >  }
> >
> >  add-next( DateTime.now.truncated-to('hour').later( :1hour )
> );
> >  }
> >  }
> >
> >
> >  react whenever every-hour() {
> >  say "it's been an hour";
> >  say "the time is $_"
> >  }
> >
> >
> >
> > Honestly it would probably be better to use something native to the
> > system to run it once an hour, in case the program dies.
> >
> >
>
> Thank you!
>
> How much impact CPU usage wise does sleep and/or react
> have on the system?
>
> My fear is I will tie up a core with my code
>


-- 
__

:(){ :|:& };:


Re: sleep 3600 vs task scheduler

2020-04-07 Thread ToddAndMargo via perl6-users
On Tue, Apr 7, 2020 at 6:02 AM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


Hi All,

Windows 7/10

Another piece of the puzzle.

I want to loop Raku program once an hour.

Is it better use `sleep 3600` or let the program
die and restart every hour from the Task Scheduler.
By better, I mean less of a CPU footprint.

`sleep` would allow the user to cancel the program
and not have it come back.

Many thanks,
-T



On 2020-04-07 19:22, Brad Gilbert wrote:

Run code once an hour:

     react whenever Supply.interval(60 * 60) {
         say "it's been an hour"
     }

Right now that gets about 0.01 seconds slower every time the interval runs.
(At least on my computer.)
So it will get 1 second later every 4 days.


Or if you want more precise control, you could do something like:

Here is an example that is more accurate, and happens at the top of the 
hour:


     sub every-hour ( --> Supply:D ) {
         supply {
             sub add-next ( $hour --> Nil ) {
                 whenever Promise.at( $hour.Instant ) {
                     emit $hour;
                     add-next( $hour.later(:1hour) );
                 }
             }

             add-next( DateTime.now.truncated-to('hour').later( :1hour ) );
         }
     }


     react whenever every-hour() {
         say "it's been an hour";
         say "the time is $_"
     }



Honestly it would probably be better to use something native to the 
system to run it once an hour, in case the program dies.





Thank you!

How much impact CPU usage wise does sleep and/or react
have on the system?

My fear is I will tie up a core with my code


Re: sleep 3600 vs task scheduler

2020-04-07 Thread Brad Gilbert
Run code once an hour:

react whenever Supply.interval(60 * 60) {
say "it's been an hour"
}

Right now that gets about 0.01 seconds slower every time the interval runs.
(At least on my computer.)
So it will get 1 second later every 4 days.


Or if you want more precise control, you could do something like:

Here is an example that is more accurate, and happens at the top of the
hour:

sub every-hour ( --> Supply:D ) {
supply {
sub add-next ( $hour --> Nil ) {
whenever Promise.at( $hour.Instant ) {
emit $hour;
add-next( $hour.later(:1hour) );
}
}

add-next( DateTime.now.truncated-to('hour').later( :1hour ) );
}
}


react whenever every-hour() {
say "it's been an hour";
say "the time is $_"
}



Honestly it would probably be better to use something native to the system
to run it once an hour, in case the program dies.


On Tue, Apr 7, 2020 at 6:02 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Windows 7/10
>
> Another piece of the puzzle.
>
> I want to loop Raku program once an hour.
>
> Is it better use `sleep 3600` or let the program
> die and restart every hour from the Task Scheduler.
> By better, I mean less of a CPU footprint.
>
> `sleep` would allow the user to cancel the program
> and not have it come back.
>
> Many thanks,
> -T
>


sleep 3600 vs task scheduler

2020-04-07 Thread ToddAndMargo via perl6-users

Hi All,

Windows 7/10

Another piece of the puzzle.

I want to loop Raku program once an hour.

Is it better use `sleep 3600` or let the program
die and restart every hour from the Task Scheduler.
By better, I mean less of a CPU footprint.

`sleep` would allow the user to cancel the program
and not have it come back.

Many thanks,
-T