3

I have some trouble with very long subroutine with hypnotoad. I need to run 1 minute subroutine (hardware connected requirements).

Firsly, i discover this behavior with:

my $var = 0;
Mojo::IOLoop->recurring(60 => sub {
    $log->debug("starting loop: var: $var");
    if ($var == 0) {
        #...
        #make some long (30 to 50 seconds)   communication with external hardware
        sleep 50; #fake reproduction of this long communication
        $var = 1;
    }
    $log->debug("ending loop: var: $var");
}) 

Log:

14:13:45 2018 [debug] starting loop: var: 0
14:14:26 2018 [debug] ending loop: var: 1 #duration: 41 seconds
14:14:26 2018 [debug] starting loop: var: 0
14:15:08 2018 [debug] ending loop: var: 1 #duration: 42 seconds
14:15:08 2018 [debug] starting loop: var: 0
14:15:49 2018 [debug] ending loop: var: 1 #duration: 42 seconds
14:15:50 2018 [debug] starting loop: var: 0
14:16:31 2018 [debug] ending loop: var: 1 #duration: 41 seconds
...

3 problems:
1) Where do these 42 seconds come from? (yes, i know, 42 seconds is the answer of the universe...)
2) Why the IOLoop recuring loses his pace?
3) Why my variable is setted to 1, and just one second after, the if get a variable equal to 0?

When looped job needs 20 seconds or 25 seconds, no problem.
When looped job needs 60 secondes and used with morbo, no problem.
When looped job needs more than 40 seconds and used with hypnotoad (1 worker), this is the behavior explained here.

If i increase the "not needed" time (e.g. 120 seconds IOLoop for 60 seconds jobs, the behaviour is always the same.

It's not a problem about IOLoop, i can reproduce the same behavior outside loop.
I suspect a problem with worker killed and heart-beat, but i have no log about that.

hurikan
  • 43
  • 4
  • 1
    `sleep` can be interrupted, say, by signals. Check `$!` and `$!{EINTR}` after the sleep call to see if that happened and check the return value of `sleep` for the number of seconds actually slept. – mob Mar 05 '18 at 18:51
  • multiple server forks are involved for same recurring (go with morbo first) – mpapec Mar 05 '18 at 21:55
  • https://metacpan.org/pod/Mojo::IOLoop::ReadWriteFork for sleep() and hw communication – mpapec Mar 05 '18 at 21:56
  • @mob My sleep duration is between 35 and 36 seconds for a `sleep 50;` And about `$!` and `$!{EINTR}`: Can you add more details? Directly from my bash terminal? If yes, `$!` return an empty variable and $!{EINTR}` return `!{EINTR}: event not found` @Сухой27 I don't think it's my actual problem. When i use hypnotoad with 2 worker, i can see the recurring loop called and logged twice, but i have the same problem. – hurikan Mar 06 '18 at 15:24
  • 1
    `$!` and `$!{EINTR}` are perl variables. – mob Mar 06 '18 at 17:19
  • So `$!` content is `Interrupted system call` and `$!{EINTR}` is `4`, just after my `sleep 50`. And the real sleep duration is 36 seconds. So, the problem come from Debian? It interrupt a too long blocking code? – hurikan Mar 07 '18 at 09:22

0 Answers0