prometheus / prometheus/client_python

Gauge and Counter allocate alot of memory

Aperta
#922 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
4.4k
Fork
876
Merge medio
8g 4h
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo il riproduttore Python fornito con prometheus-client 0.17.0 e Python 3.9, misurando sia i singoli oggetti metrica sia prometheus_client.REGISTRY. Il lavoro è completato quando si stabilisce se le allocazioni segnalate sono previste oppure si identifica una regressione concreta della memoria, con un obiettivo mirato per un test o per la documentazione, se il repository ne fornisce uno.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
observability
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.