prometheus / prometheus/client_python
Gauge and Counter allocate alot of memory
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 876
- 平均合并
- 8 天 4 小时
- 30 天内合并 PR
- 1
描述
Hey, I've noticed that a prometheus Gauge or Counter object needs alot of memory. Is this a normal/expected behaviour?
import prometheus_client
import objsize
labels={}
labels['test']='test'
print("Memory Registry at Start: " +str(objsize.get_deep_size(prometheus_client.REGISTRY)))
print("Memory Labels as dict: "+ str(objsize.get_deep_size(labels)))
gauge = prometheus_client.Gauge("test", "", list(sorted(labels.keys())))
gauge.labels(**labels).set(10)
print("Memory Gauge object: "+ str(objsize.get_deep_size(gauge)))
print("Memory Registry after one Gauge: "+str(objsize.get_deep_size(prometheus_client.REGISTRY)))
gauge2 = prometheus_client.Gauge("test2", "")
gauge2.set(10)
print("Memory Gauge object: "+ str(objsize.get_deep_size(gauge2)))
print("Memory Registry after second Gauge: "+str(objsize.get_deep_size(prometheus_client.REGISTRY)))
counter = prometheus_client.Counter("test3", "", list(sorted(labels.keys())))
counter.labels(**labels).inc(10)
print("Memory counter object: "+str(objsize.get_deep_size(counter)))
print("Memory Registry after Counter: "+str(objsize.get_deep_size(prometheus_client.REGISTRY)))
labels={}
labels['test']='test2'
gauge.labels(**labels).set(10)
print("Memory Gauge second label: "+str(objsize.get_deep_size(gauge)))
print("Memory Registry end: "+str(objsize.get_deep_size(prometheus_client.REGISTRY)))
results in this memory usage:
Memory Registry at Start: 3988
Memory Labels as dict: 285
Memory Gauge object: 2418
Memory Registry after one Gauge: 6725
Memory Gauge object: 1051
Memory Registry after second Gauge: 7723
Memory counter object: 2108
Memory Registry after Counter: 10027
Memory Gauge second label: 3376
Memory Registry end: 10931
In this Blog Post https://www.robustperception.io/memory-usage-of-prometheus-client-libraries/ ( I know it's old) a counter needed way less memory than in my usecase. I'm using python 3.9, on windows(but i've got the same problem in a docker container) and prometheus-client 0.17.0
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 prometheus-client 0.17.0 和 Python 3.9 运行所提供的 Python 复现程序,同时测量单个指标对象和 prometheus_client.REGISTRY。完成的标准是确定报告的内存分配是否符合预期,或识别出具体的内存回归;如果 repository 提供了相应目标,还应有一个聚焦的测试或文档目标。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- observability
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100