Skip to content

labels method lead to memory leak #937

Open
@zhaozhiming37

Description

@zhaozhiming37

I find metrics in my celery task will lead to memory leak. And I reproduced this problem issue locally.

import tracemalloc
from prometheus_client import Counter

counter_a = Counter('request_count_a', 'request count to a', ['name'])
counter_b = Counter('request_count_b', 'request count to b')

tracemalloc.start()
for _ in range(10):
    counter_a.labels('a').inc()
    curr_mem, peak_mem = tracemalloc.get_traced_memory()
    print(f"curr mem: {curr_mem / 10**3} Kb, peak mem: {peak_mem / 10**3} Kb")

print("*****************************************")

for _ in range(10):
    counter_b.inc()
    curr_mem, peak_mem = tracemalloc.get_traced_memory()
    print(f"curr mem: {curr_mem / 10 ** 3} Kb, peak mem: {peak_mem / 10 ** 3} Kb")

It seems to be caused by the labels method. PS: prometheus-client==0.17.1
mem

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions