Slow hgweb.cgi
Dominik Psenner
dpsenner at gmail.com
Thu Apr 14 02:20:53 CDT 2011
> Then, the last thing I can think of is to instrument the hgweb
> CGI/WSGI to gather and dump profiling information, just like the
> --profile command line option. The code for such option is at:
>
> http://selenic.com/hg/file/b032bec2c0a6/mercurial/dispatch.py#l613
>
> From line 613. Unfortunately, I don't fully understand how it works
> to give you any advice. Maybe even there is a sample CGI/WSGI script
> already configured for profiling.
If it's not documented anywhere, from now on it is. I hacked:
#!/usr/bin/env python
def main():
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/var/hg/hgweb.config"
# let the output be UTF-8
import os;
os.environ["HGENCODING"] = "UTF-8"
# Uncomment and adjust if Mercurial is not installed system-wide:
#import sys; sys.path.insert(0, "/path/to/python/lib")
# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb; cgitb.enable()
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb(config)
wsgicgi.launch(application)
import profile;
profile.run("main()")
And then executed on the server:
$ export SCRIPT_NAME="hgweb.cgi"
$ ./hgweb.profile.cgi
Hooray!
PS: this story feels a lot like hacking ;-)
More information about the Mercurial-devel
mailing list