What's new? | Help | Directory | Sign in
Google
django-jits
Django JITS (Just In Time Scheduler)
  
  
  
    
Search
for
Updated Mar 19, 2008 by mikeal.rogers
Labels: Featured
InstallAndConfig  
Installation and Configuration.

Installation

First you'll need to install setuptools.

wget http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py

Once you have setuptools installed you'll need to use easy_install to install jits.

sudo easy_install jits

Configuration

Once jits is installed in to your local Python you'll need to enable it in your django project.

You'll want to edit your settings.py file.

Find the MIDDLEWARE_CLASSES variable, by default it looks like this:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

You'll need to add the jits middleware class.

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'jits.middleware.JitsMiddleware',
)

Since jits requires some model data you'll also need to enable the jits django application. Find the INSTALLED_APPS variable, by default it looks like:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'mysite.app',
)

You'll need to add the jits application

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'mysite.app',
    'jits.app',
)

At this point you can start using jits in your django application. However, there are some additional options you may want to set in your settings.py file.

JITS_THREADED    = False
JITS_NUM_THREADS = 10
JITS_MIN_SECONDS = 5
JITS_MIN_MINUTES = 0

The sample above is actually the default settings for all those options.

Since polling for scheduled tasks happens when a new request comes in jits will block on satisfying the request until the tasks are done. This blocking mode is the default since it's great for debugging, but in production you may have hundreds of tasks that get kicked off by a single request and blocking would be very bad. Setting JITS_THREADED to True will spawn a thread when polling and kicking off the next round of scheduled tasks instead of blocking the request.

When jits is running threaded, it will also use a threadpool for running all scheduled tasks in parallel. You can set the number of threads to use with JITS_NUM_THREADS.

Making a SQL query on every single HTTP request is a bit much, so JITS has an optimization that checks how long it's been since the last poll. If the minimum time hasn't lapsed it won't try to poll for scheduled tasks to run. By default this is set to 5 seconds but you can make it longer, or shorter, by setting JITS_MIN_SECONDS and/or JITS_MIN_MINUTES.


Sign in to add a comment