Mojolicious: long subroutine have no effect on my variable

107 Views Asked by At

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.

0

There are 0 best solutions below