[TransWarp] scheduling bug or my fault?

Phillip J. Eby pje at telecommunity.com
Mon Aug 18 15:20:56 EDT 2003


At 08:46 PM 8/18/03 +0200, Matthias Drochner wrote:

>Just tried to find out how get a mix of background and interactive
>tasks, and found that an AdaptiveTask is scheduled in a very uneven
>way: in my appended test program, invocations happen pairwise, two
>calls close together, followed by the intended 10s delay.
>Is there a bug or am I doing something wrong?

Neither, really.  It's just that adaptive task scheduling isn't 
cron.  Tasks are scheduled relative to *themselves*, not relative to other 
tasks.  At any given moment, the task queue runs the highest-priority task 
that is available for execution; i.e., whose current scheduling interval 
has passed.  At the completion of the task, its next availability is scheduled.

In your example, the tasks take almost no time to execute, and you made all 
the tasks available to execute at the beginning.  So the scheduler executes 
one, finds it has another available, and executes that one.  Then, ten 
seconds later, both will be eligible again.

You could schedule the initial adds using something like:

     self.reactor.callLater(n, self.tq.addTask, task)

Where n is the number of seconds from now that you want 'task' to be added 
to the queue.

Note, however, that since task scheduling intervals are relative, if you 
are doing any task that takes a measurable amount of time, the relative 
scheduling of individual tasks is likely to drift.




More information about the PEAK mailing list