TracをWSGIで高速化

FastCGITracを動かしていると、もっさりしているので、静的ファイルを分離した上でWSGIを使うようにして高速化してみた。

静的ファイルの分離

Trac を設置するときは静的ファイルを分離すると速い - まちゅダイアリー(2008-03-13)に書いてあるとおりにやりました。

WSGI

まずmod_wsgiPython 2.7で動かすようにインストール。(ここでバージョンを間違えると、またリポジトリブラウザが表示されないといった問題が発生する)

sudo port install mod_wsgi +python27

/opt/local/share/trac/contrib/cgi-binに配置したtrac.wsgiの内容。(ImportError: No module named trac.web.mainというエラーが出たのでimport部分を追加)

import os
os.environ['TRAC_ENV_PARENT_DIR'] = '/Trac'
os.environ['PYTHON_EGG_CACHE'] = '/opt/local/var/apache2/.python-eggs'

import site
site.addsitedir('/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages')

import trac.web.main
application = trac.web.main.dispatch_request

httpd.conf の設定。

WSGIScriptAlias /trac /opt/local/share/trac/contrib/cgi-bin/trac.wsgi
WSGIDaemonProcess trac user=_www group=_www processes=2 threads=25 maximum-requests=10000 python-path=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
WSGIProcessGroup trac

<Location /trac>
  WSGIApplicationGroup %{GLOBAL}
  Order allow,deny
  Allow from all
</Location>

これでかなり速くなった。

WSGIウェブプログラミング

WSGIウェブプログラミング