金字塔 debugtoolbar 导致内存 "leak"

Pyramid debugtoolbar causing memory "leak"

我的金字塔应用有一个很长的 运行ning 任务(约 30 分钟)。当调试工具栏打开时,内存使用量 (RSS) 开始超过 30GB,这导致 OOM 杀手杀死整个 Python 进程。

当我关闭调试工具栏时,RSS 在任务期间始终保持在 500MB 以下 运行,内存使用完全没有问题。

我可以为开发模式关闭 debugtoolbar,但出于显而易见的原因,我想将其保持打开状态。

我正在寻找解决此问题的可能方法,例如:

  1. 在 运行 任务之前关闭调试工具栏,并在任务完成后打开

  2. 每隔一段时间告诉调试工具栏 "forget" 跟踪对象(在 运行 执行任务期间)

  3. 调试工具栏的任何其他开关、标志,可以减少其内存使用。

解决方案?

pyramid_debugtoolbar 实现为捕获应用程序大量状态的补间。所有这些状态都存储在进程内存中,因此当您访问调试工具栏时,您可以访问该信息。

但是,您可以使用 .ini 设置为应用程序中的某些路径关闭 pyramid_debugtoolbar

debugtoolbar.exclude_prefixes

此处记录:http://docs.pylonsproject.org/projects/pyramid-debugtoolbar/en/latest/#settings

The debug toolbar won’t be shown and no data will be recorded if the PATH_INFO variable starts with any of the prefixes listed in this setting.

如有必要,您可以提供路径列表。