Skip to content

Hit ratio statistics #210

Open
Open

Description

@masoudsafa

Hi guys
In order to monitor and improve my app, i need to know number of calls and cache hit ratio per key in certain intervals. is it possible with dogpile?

Activity

  1. zzzeek commented on Aug 29, 2021

    @zzzeek
    Member

    I would implement this by intercepting calls to the backend, which you can do using ProxyBackend. we can add examples to https://dogpilecache.sqlalchemy.org/en/latest/recipes.html if someone wants to come up with this.

  2. megan-carey commented on Nov 19, 2021

    @megan-carey

    Upvote for adding a metrics collection example to the recipes page :)

  3. jvanasco commented on Jan 17, 2022

    @jvanasco
    Member

    FWIW, I open sourced a Pyramid plugin to do this a few years ago, which illustrates how to accomplish this.

    The package offers a DogpileLoggingProxy proxy object - derived from ProxyBackend - which is used to track all the Dogpile API calls, and stashes the metrics on the request object.

    https://github.com/jvanasco/pyramid_debugtoolbar_dogpile

  4. glaucocustodio commented on Aug 11, 2023

    @glaucocustodio

    If you are using Redis as backend, you should override set_serialized and get_serialized instead as get and set are not implemented on this backend. Eg:

    from dogpile.cache import make_region
    from dogpile.cache.proxy import ProxyBackend
    from dogpile.cache.api import NO_VALUE
    
    class ReportingProxy(ProxyBackend):
        def set_serialized(self, key, value):
            # report cache miss
            self.proxied.set_serialized(key, value)
    
        def get_serialized(self, key):
            cached = self.proxied.get_serialized(key)
    
            if cached != NO_VALUE:
                # report cache hit
                pass
    
            return cached
    
    region = make_region().configure(
        'dogpile.cache.redis',
        arguments={
            'url': 'redis://localhost:6379/0',  # Redis connection URL
            'distributed_lock': True,  # Use distributed lock to prevent dogpiling
            'thread_local_lock': False,
        },
        wrap=[ReportingProxy],
    )
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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions