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.

Tags: , , , , ,

Leave a Reply