mod_python Trac实例性能分析

发布于 2024-10-28 03:56:13 字数 515 浏览 4 评论 0原文

我想在我们现实世界的 Trac/mod_python 安装中启用侧面日志记录,该安装已经变得相当慢(很多插件,没有那么多票证/页面)。

我可以代理请求对象,或者添加python跟踪(带有每次调用的时间戳)吗?是否有针对此类包装器的机制?

Trac/mod_python 中的主要入口点是

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

,我想我应该安装一个包装器,它可以通过所有插件跟踪 python 调用以进行时序分析。可能的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-11-04 03:56:13

使用 cProfile 模块,类似这样的东西应该可以工作:

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

然后应分析每个请求,并将分析数据(显示占用时间)保存在指定位置,每个请求一个带有时间戳的文件。当然,正在运行的进程必须具有该文件的写入权限。

您可以更改源中的文件。

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.

轮廓§ 2024-11-04 03:56:13

您可能需要查看此页面,其中描述了一个人的识别技术并解决 Trac 性能问题。每当我的 Trac 实例开始变得缓慢时,我就会借鉴那里解释的技术。

Trac wiki 上的 TracPerformance 页面提供了许多有关提高性能的好建议。

此服务器故障问题还发布了一些有用的提示和链接。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文