periodic tasks could use a refactoring

Bug #939087 reported by Chris Behrens
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Michael Still

Bug Description

Right now, you declare periodic tasks with the @manager.periodic_task decorator.. It accepts a # of ticks to specify interval to run.

The issue I have is that changing FLAGS.periodic_interval will modify every periodic task. It's also slightly annoying to have to compute # of seconds you'd like to run a task at... based on dividing it by the setting of periodic_interval to get # of ticks.

Rough ideas of what I'd like to do for Folsom:

change @manager.perodic_task() to allow keyword args of "enabled" and "interval". interval is in seconds. "ticks" goes away.

Modify the task runner to be a bit more smart. Since it has a list of periodic tasks to run (and it can ignore ones that are enabled=False).. it can figure out the amount of time it needs to sleep to run the next task. Essentially the task runner can sit in a greenthread sleeping until the next periodic task should run based on its "interval" setting.

Something like that :) Other ideas welcomed!

Chris Behrens (cbehrens)
Changed in nova:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Chris Behrens (cbehrens) wrote :

Another example: If you want a periodic task to run at 5 seconds, but poll_interval is 60s.. you can't do that right now without modifying poll_interval down to 5s. Then you would need to go up the 'ticks' for every other task by 12x.

Revision history for this message
Zhongyue Luo (zyluo) wrote :

What is your opinion on making it configurable for the periodic task to be event-driven?

I'm devising a blueprint to let all the messaging and status updating to be event-driven for Folsom.

Revision history for this message
Chris Behrens (cbehrens) wrote :

I like event-driven in general. :) I'm having trouble understanding it in the context of tasks that just need to be run on some interval not related to any other event.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/18618

Changed in nova:
assignee: nobody → Michael Still (mikalstill)
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/18618
Committed: http://github.com/openstack/nova/commit/9fb647ec100133b1ee5903535507c74d408f4790
Submitter: Jenkins
Branch: master

commit 9fb647ec100133b1ee5903535507c74d408f4790
Author: Michael Still <email address hidden>
Date: Mon Dec 24 15:00:52 2012 +1100

    Refactor periodic tasks.

    This review allows periodic tasks to be enabled or disabled in the
    decorator, as well as by specifying an interval which is negative.

    The spacing between runs of a periodic task is now specified in
    seconds, with zero meaning the default spacing which is currently 60
    seconds.

    There is also a new argument to the decorator which indicates if a
    periodic task _needs_ to be run in the nova-compute process. There is
    also a flag (run_external_periodic_tasks) which can be used to move
    these periodic tasks out of the nova-compute process.

    I also remove the periodic_interval flag to services, as the interval
    between runs is now dynamic based on the number of seconds that a
    periodic task wants to wait for its next run. For callers who want to
    twiddle the sleep period (for example unit tests), there is a
    create() argument periodic_interval_max which lets the period
    periodic_tasks() specifies be overridden. This is not exposed as a
    flag because I cannot see a use case for that. It is needed for unit
    testing however.

    DocImpact. Resolves bug 939087.

    Change-Id: I7f245a88b8d229a481c1b65a4c0f1e2769bf3901

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → grizzly-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: grizzly-2 → 2013.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.