TileCache on Windows part 2: mod_python


The 5 minute install guide for TileCache on Windows I wrote last weekend was intended to show how easy it is to get a TileCache map server up and running. Now that it works, we should be concerned with performance. As my colleague StevenO pointed out, a CGI solution is probably not the way to go if you want to take it to production level. So I decided to try a different approach: install TileCache as a module into the local Python setup and have mod_python handle the python scripts of which TileCache is made up directly. That way, we can dispose of the CGI wrapper and thus the need to call the python interpreter for every tile request being made by the client. In theory, that should give us a huge performance gain.I’m going to look into two topics:

  1. Getting TileCache to run under mod_python
  2. Benchmarking TileCache and more optimazition techniques

The first topic will be covered in this post, the second in a future post.Getting TileCache to run under mod_pythonI’m going to assume we have a Apache / TileCache setup like the one we ended up with in the 5 minute install guide I wrote. If you’re not there yet and want to follow my lead, I suggest you read that one first. It will only take 5 minutes :)These are the steps to take to set it up:

  • Get the mod_python installer (direct download link – always check the site for the latest version)
  • Run the installer. At one point it may ask you to locate your Apache installation. Point it to C:\Program Files\Apache Software Foundation\Apache2.2\
  • When the installer is done, locate the main Apache configuration file, which is in C:\Program Files\Apache Software Foundation\Apache2.2\conf\, and open it in your favourite text editor. No, not in Word. In this file, find the group of LoadModule directives and paste this line at the bottom:

LoadModule python_module modules/mod_python.so

  • While you’re there, add the Directory directive for the TileCache dir:
# THIS IS FOR TILECACHE UNDER MOD_PYTHON
<Directory /Program Files/Apache Software Foundation/Apache2.2/htdocs/tilecache/>
	AddHandler python-program .py
	PythonHandler TileCache.Service
	PythonOption TileCacheConfig C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/tilecache/tilecache.cfg
</Directory>
  • Don’t worry careful reader, we will create this directory now: go to C:\Program Files\Apache Software Foundation\Apache2.2\htdocs and create a directory ’tilecache’ in there.
  • Extract tilecache-2.0.tar.gz (I assume you still have it from the first episode) in that directory.
  • Now we’re going to install TileCache in Python . Open C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\tilecache\setup.py in your text editor and change line 33 to
data_files=['tilecache.cfg'],
  • Save and close the file.
  • Now open a DOS box and cd to C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\tilecache\ and execute the following line:
c:\python25\python.exe setup.py install

Now Python knows about TileCache and we’re good to go – as soon as we restarted Apache to make it aware of the config file changes. You can do so by invoking the restart script from the start menu or from C:\Program Files\Apache Software Foundation\Apache2.2\bin\ApacheMonitor.exeTo test the new mod_python setup, try

http://localhost/tilecache/tilecache.py/1.0.0/basic/0/0/0.png

This should give you a tile. If it doesn’t, read more carefully. If it still doesn’t, come and beat me at foosball – you’ll find that not too hard.

3 thoughts on “TileCache on Windows part 2: mod_python

  1. hi,
    that totally worked thanks a bunch! could you post a word or two what that setup script is doing, that it magically makes TileCache work under mod_python (and gets rid of those pesky cant find module etc errors)?

  2. MOD_PYTHON ERROR

    ProcessId: 804
    Interpreter: ‘localhost.local.domain’

    ServerName: ‘localhost.local.domain’
    DocumentRoot: ‘C:/ms4w/Apache/htdocs’

    URI: ‘/tilecache/tilecache.py/1.0.0/basic/0/0/0.png’
    Location: None
    Directory: ‘C:/ms4w/Apache/htdocs/tilecache/’
    Filename: ‘C:/ms4w/Apache/htdocs/tilecache/tilecache.py’
    PathInfo: ‘/1.0.0/basic/0/0/0.png’

    Phase: ‘PythonHandler’
    Handler: ‘TileCache.Service’

    Traceback (most recent call last):

    File “C:\Python25\Lib\site-packages\mod_python\importer.py”, line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

    File “C:\Python25\Lib\site-packages\mod_python\importer.py”, line 1202, in _process_target
    module = import_module(module_name, path=path)

    File “C:\Python25\Lib\site-packages\mod_python\importer.py”, line 304, in import_module
    return __import__(module_name, {}, {}, [‘*’])

    ImportError: No module named TileCache.Service

  3. Hi !
    Thanks for your tutorial !
    I had problems with loading python_module. Apache server didn’t find it.
    After some researches, I found out that the problems were because compatibilities versions between apache server, mod_pyhton.
    I will list here the versions that works for me :
    1. XAMPP 1.7.7 – http://www.apachefriends.org/en/xampp-windows.html#641
    2. mod_python-3.2.10.win32-py2.4-apache2.2 – http://archive.apache.org/dist/httpd/modpython/win/3.2.10/
    3. python 2.4 – http://www.python.org/download/releases/2.4/http://www.python.org/download/releases/2.4/

    About the string, data_files=[’tilecache.cfg’], , that must to be inserted at line 33 into setup.py.
    I think the number of line is wrong. Bellow are the lines that contain data_files=[’tilecache.cfg’],

    setup(name=’TileCache’,
    data_files=[’tilecache.cfg’],
    version=’2.11′,
    description=’a web map tile caching system’,
    author=’TileCache Contributors’,
    author_email=’tilecache@lists.osgeo.org’,
    url=’http://tilecache.org/’,
    long_description=readme,
    packages=[‘TileCache’, ‘TileCache.Caches’, ‘TileCache.Services’, ‘TileCache.Layers’],
    scripts=[’tilecache.cgi’, ’tilecache.fcgi’,
    ’tilecache_seed.py’, ’tilecache_install_config.py’,
    ’tilecache_clean.py’, ’tilecache_http_server.py’],
    zip_safe=False,
    test_suite = ‘tests.run_doc_tests’,
    license=”BSD”,
    classifiers=classifiers,
    entry_points = “””
    [paste.app_factory]
    main = TileCache.Service:paste_deploy_app
    “””
    )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s