开发者

Performance Analysis of mod_python Trac instance

I would like to enable a side-logging in our real-world Trac/mod开发者_如何学编程_python installation that has gotten quite slow (lots of plugins, not so many tickets/pages).

Can I proxy the request object, or add a python trace (with timestamps for each call) somehow? Is there e mechanism for these kind of wrappers?

The main entry point in Trac/mod_python is

def handler(req):
    pkg_resources.require('Trac==%s' % VERSION)
    gateway = ModPythonGateway(req, req.get_options())
    from trac.web.main import dispatch_request
    gateway.run(dispatch_request)
    return apache.OK

and there I guess I should install a wrapper, that can trace python calls through all plugins for timing analysis. Possible?


Using the cProfile module, something like this should work:

def handler(req):
    pkg_resources.require('Trac==%s' % VERSION)
    gateway = ModPythonGateway(req, req.get_options())

    from trac.web.main import dispatch_request
    import cProfile
    from datetime import datetime

    def profile_request(*args, **kwargs):
        p = cProfile.Profile()
        p.runcall(dispatch_request, *args, **kwargs)
        # log to a file
        timestamp = datetime.now().strftime('%Y-%m-%d_%H%M%S.%f')
        p.dump_stats('/var/log/trac_profile/%s' % timestamp)

    gateway.run(profile_request)
    return apache.OK

Then each request should be profiled and the profiling data (showing what takes up time) saved in the specified location, one timestamped file per request. The running process, of course, must have write privileges to the file.

You can change the file in the source.


You may want to check out this page describing one person's technique for identifying and resolving Trac performance problems. I borrow from the techniques explained there whenever my Trac instance starts to get sluggish.

The TracPerformance page on Trac's wiki has many more good pointers about improving performance.

There are also some useful hints and links posted to this serverfault question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜