it was just a trial.
Explaining it further, let's see if someone spots the **supposed** 
implementation error....

In order to separate transactions and avoid "task contention" among several 
workers, we need the **master** steps to both assign tasks and process 
tasks.

The **thread** steps inserts a virtual "assign the task" job setting the 
do_assign_task flag to True when necessary.
When that is found to be true, **worker** assigns tasks and sleeps for 3 
seconds, giving the change to the send_heartbeat() to reset the 
do_assign_task to False, so you don't have consecutive "assign_tasks" over 
and over.

Skipping over the actual steps taken, a **master** does a loop and sleeps. 

In that loop, if do_assign_task is True, it assign tasks, returns "None" 
--> goes to sleep for 3 seconds

A **thread** does some cleanup, sleeps for 3 seconds and sets the 
do_assign_task every 5 cycles.

Ok, to be fair it's not guaranteed that a loop in either of those completes 
in 3 seconds, but the **steps** for both (when the **worker** doesn't 
anything) take a few ms (i.e. scheduler doesn't take into account how many 
ms passed between the start of either loop before setting the sleep of 3 
seconds...)

So, self.sleep() in normal condition gets called:
- at every loop of the **thread** (at the end of the send_heartbeat())
- at every loop of the **master** when it has no tasks or when it assign 
tasks (at the end of the loop() function)  

What you are experiencing is that, even if the **thread** sets correctly 
do_assign_tasks = True, when the **worker** tries to pop something for some 
reason do_assign_task is False.
I can imagine that such a thing happens because do_assign_task is reset to 
False, but that reset happens only after (at least) 3 seconds, at the next 
send_heartbeat() call.
What I can't reproduce is this behaviour exactly.... how is it possible 
that in your logs the "I'm a ticker" message comes 40 ms before pop_task, 
and do_assign_task is yet False ?  
Can you add a logging line just between these two lines
            self.do_assign_tasks = False
            if counter % 5 == 0 or mybackedstatus == PICK:
and between
                    if self.worker_status[0] == ACTIVE:
                        self.do_assign_tasks = True

so we can monitor exactly when the flag is switched ?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to