uWSGI日志解析器,用于查找内存消耗者
项目描述
pyuwsgimemhog
你想找出在uWSGI下运行的应用程序中哪个路径导致内存泄漏吗?
pyuwsgimemhog 解析uWSGI日志,指出哪些路径导致uWSGI进程RSS内存增加。
安装
pip install pyuwsgimemhog
需求
为了获得所需的信息,您必须以 memory-report 启用运行uWSGI。
请注意,只有在使用每个进程一个线程的情况下,才能获得有意义的结果。
从命令行使用
您需要将单个uWSGI日志文件传递给 pyuwsgimemhog
pyuwsgimemhog --logfile /path/to/log /api 975 200 4.9 /another-api 502 2 251
这意味着 /api 导致内存使用量增加975MB,已计数200次,每次调用贡献4.9MB。/another-api 在两次出现中贡献了502MB,因此每次调用贡献251MB。
作为库使用
除了将 pyuwsgimemhog 作为命令行实用程序使用外,还可以将其作为库使用。这允许将自定义路径归一化函数传递给日志分析器,以便根据该URL路径对请求进行分组。
使用Django URL解析器对URL进行归一化的简单示例如下
from django.urls import resolve, Resolver404
from pyuwsgimemhog.pyuwsgimemhog import normalize_path, uwsgimemhog
from urllib.parse import urlparse
def normalize(url):
try:
return resolve(urlparse(url).path).view_name
except Resolver404:
# This view was not handled by Django so fall back to the default
# normalization. Use normalize_path_with_nums to normalize numbers
# in path to 0.
return normalize_path(url)
with open(logfile, 'r') as f:
for view, memory, count in uwsgimemhog(
f, threshold * 1_000_000, normalize):
print('{} {} {} {:.1f}'.format(
view, memory // 1_000_000, count, memory / count / 1_000_000
))
许可证
MIT许可证
致谢
此包是用 Cookiecutter 和 audreyr/cookiecutter-pypackage 项目模板创建的。
历史
0.3.0 (2021-04-24)
使传递自定义归一化函数成为可能(Terence D. Honles)
修复正则表达式以要求RSS(Terence D. Honles)
使用 Github Actions 代替 Travis (Terence D. Honles)
0.2.0 (2020-01-10)
计数并显示出现次数和每调用泄漏计数。
0.1.0 (2019-04-12)
首次发布在 PyPI 上。
项目详情
关闭
pyuwsgimemhog-0.3.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 5309f4d16ad2a930273895c3594ba3825aba508e755a22e0415bba5280b8f02a |
|
MD5 | f061307d3beb0dad03a01b1033884acf |
|
BLAKE2b-256 | decea70ff4cedb08441a6f741d0a3f3ec152584dfdae9cb066e63dbbc70c3d79 |