Speedup of Trac Static Content

At work I recently spent some time working on getting our hosted Trac to run faster. I found one simple little trick that gave up to a 20% speed improvement, so I thought I'd share it here.

The basic idea is that Trac has a lot of overhead due to executing a pile of Python code for each requested file including static content like the logos, background images, CSS, etc. If you tell Apache just to skip the Python code for the static content you can save a lot of time and processing power. All the default static content is under "/python/library/path/site-packages/trac/htdocs" which Trac servers up as "/chrome/common/". Basically a request for http://server.com/trac/chrome/common/logo.png will get a file from somewhere like /usr/lib/python2.5/site-packages/trac/htdocs/logo.png on the harddisk. To skip Trac for this we want to add something like the following to the Apache configuration (AliasMatch is part of mod_alias):

 	AliasMatch ^/(.+)/chrome/common(.*) /usr/lib/python2.5/site-packages/trac/htdocs$2
 

This matches any request for a path that matches /something/chrome/common/something_else, and then sends back the file located at /usr/lib/python2.5/site-packages/trac/htdocs/something_else; preventing the Trac Python code from running. Since there is about a dozen images, CSS files, and JavaScript files for each Trac page the time saved by this very quickly adds up.

Categories: Computers, Linux, Work
Date: 2010-08-25 23:03:54, 14 years and 122 days ago

Leave reply

No html allowed in reply

Notify me of follow-up comments via email.