Skip to content

python_gc_duration_seconds gone between 0.4 and 0.7 #429

Closed

Description

@gjcarneiro

I have always found the python_gc_duration_seconds Histogram extremely useful to track down latency problems in Python caused by the GC. But this metric seems to have disappeared when I upgraded client_prometheus from 0.4 to 0.7. Any chance to get it back? Pretty please?

Activity

  1. gjcarneiro commented on Jun 17, 2019

    @gjcarneiro
    Author

    Looks like this disappeared when #371 got merged.

  2. gjcarneiro commented on Jun 17, 2019

    @gjcarneiro
    Author

    I end up just adding back simplified similar code into my app. In case anyone else needs it:

    import gc
    import time
    from prometheus_client import Histogram
    
    
    PYTHON_GC_DURATION = Histogram(
        "python_gc_duration_seconds",
        "Time spent in garbage collection",
        ["generation"],
    )
    
    _python_gc_times = {}
    _gc_cb_active = False
    
    
    def _python_gc_cb(phase, info):
        global _gc_cb_active
        try:
            if _gc_cb_active:
                return
            _gc_cb_active = True
    
            gen = info["generation"]
            if phase == "start":
                _python_gc_times[gen] = time.monotonic()
            if phase == "stop":
                delta = time.monotonic() - _python_gc_times[gen]
                PYTHON_GC_DURATION.labels(gen).observe(delta)
        finally:
            _gc_cb_active = False
    
    
    gc.callbacks.append(_python_gc_cb)

    At the risk of a deadlock, sure. But, to be honest, I have never experienced such a deadlock, I'll take my chances for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions