trac performance

There are suggestions for improving performance at http://trac.edgewall.org/wiki/TracPerformance. With my existing configuration I had it typical page loads are taking 4 to 5 seconds, after making the changes below typical page loads are around a second, some faster some slower (loading the first page takes longer).

Related Posts

Switch to using mod_wsgi rather than mod_python

Remove the apache configuration for trac
sudo vi /etc/apache2/sites-enabled/000-default
Remove the lines that are struck through below
<Location /trac>
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /var/trac/projects
PythonOption TracUriRoot /trac
PythonOption PYTHON_EGG_CACHE /tmp
AuthType Digest
AuthName "Subversion Repo"
AuthDigestDomain /trac
AuthDigestProvider file
AuthUserFile /etc/apache2/dav_svn.htdigest
Require valid-user
</Location>
Uninstall mod python and install mod_wsgi
sudo apt-get remove --purge libapache2-mod-python
sudo apt-get install libapache2-mod-wsgi
Now configure WSGI (I found good help for this at https://code.google.com/p/modwsgi/wiki/IntegrationWithTrac.
sudo mkdir /var/trac/cgi-bin
sudo vi /var/trac/cgi-bin/trac.wsgi
I then put this content in to trac.wsgi
#!/usr/bin/python

# -*- coding: utf-8 -*-

#

import sys

sys.stdout = sys.stderr

import os

os.environ[‘TRAC_ENV_PARENT_DIR’] = ‘/var/trac/projects’

os.environ[‘PYTHON_EGG_CACHE’] = ‘/tmp’



import trac.web.main



application = trac.web.main.dispatch_request
Ensure that the script is accessible to apache and executable
sudo chown www-data:www-data -R /var/trac/cgi-bin

sudo chmod +x /var/trac/cgi-bin/trac.wsgi 
Now to configure Apache
sudo vi /etc/apache2/sites-enabled/000-default
Add the following after the last </Directory> element
        WSGIScriptAlias /trac /var/trac/cgi-bin/trac.wsgi


        <Directory /var/trac/cgi-bin>

                WSGIApplicationGroup %{GLOBAL}

                Order deny,allow

                Allow from all

        </Directory>
Restart Apache
sudo /etc/init.d/apache2 restart
I then tested trac and it was still functioning as before 🙂

Mapping Static Resources

By default static resources like style sheets and images are served by trac itself, it is more efficient to have Apache serve these directly rather than get trac to serve them.
First extract the static resources and delete the ones we do not want (I don’t want cgi-bin as I’ve already configured it, and I don’t want htdocs/site because I will directly reference the files in the trac install).
sudo trac-admin /var/trac/projects/play deploy /var/trac/static

sudo rm -rf /var/trac/static/cgi-bin/

sudo rm -rf /var/trac/static/htdocs/site/

sudo chown www-data:www-data -R /var/trac/static
Now configure Apache to directly serve the static resources
sudo vi /etc/apache2/sites-enabled/000-default
Add the following after the last </Directory> element
Alias /trac/play/chrome/common /var/trac/static/htdocs/common

Alias /trac/play/chrome/site /var/trac/projects/play/htdocs/

<Directory “/var/trac/static/htdocs/common“> Order allow,deny
Allow from all</Directory><Directory “/var/trac/projects/play/htdocs/“> Order allow,deny Allow from all</Directory>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top