Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache miss logging #165

Closed
wants to merge 1 commit into from
Closed

Add cache miss logging #165

wants to merge 1 commit into from

Conversation

sbrunner
Copy link
Contributor

It's relay useful to know which keys is regenerated.

Copy link
Collaborator

@4383 4383 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Thanks for these changes, see my comments inline.

@@ -879,6 +882,7 @@ def get_value():
value.metadata["ct"]
)
):
log.info('Cache miss for key: %s', orig_key)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reword this with something like Missing cache for key: %s

@@ -32,6 +33,8 @@

"""

log = logging.getLogger('c2cwsgiutils.' + __name__)
Copy link
Collaborator

@4383 4383 Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use c2cwsgiutils here?
The module name is not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, missing to remove ...

Copy link
Collaborator

@4383 4383 Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe no problems :)

@sbrunner
Copy link
Contributor Author

Thanks @4383 , done :-)

@4383 4383 requested a review from sqla-tester October 18, 2019 14:34
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work to try to get revision 0b7a5fb of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 0b7a5fb: https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hervé Beraud (4383) wrote:

Code-Review-1

(1 comment)

Some comment related to your commit message:

  • /COMMIT_MSG (line 9): I think we can reword the commit message with something like:
Log missing cache keys

When a cache is missing then we log the key to provide some useful informations to users.

Copy link
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi there -

There was no issue opened for this so this is the first chance we have to talk about the subject area here of "region should include logging". It should! great idea. But I like to create a full feature rather than adding one liners, that is, think about what people would usually want in this area, not just one thing that we thought of. Please review a few comments I have as far as if we do have logging in region, things we would reasonably expect someone to see in those logs. also I hope that you can review the existing logging that's in lock.

as far as tests, I can relax that there are not tests for these logging statements for now as there are also no tests for the logging in lock.py.

dogpile/cache/region.py Outdated Show resolved Hide resolved
dogpile/cache/region.py Outdated Show resolved Hide resolved
dogpile/cache/region.py Outdated Show resolved Hide resolved
dogpile/cache/region.py Outdated Show resolved Hide resolved
@sqla-tester
Copy link
Collaborator

mike bayer (zzzeek) wrote:

(1 comment)

@sbrunner
Copy link
Contributor Author

@zzzeek I see your comments, I will work on them the next week :-)

@sbrunner
Copy link
Contributor Author

@zzzeek For me do the changes for all your comment, is it OK for you, are the message good or should be improved?
Thanks in advance :-)

@zzzeek
Copy link
Member

zzzeek commented Oct 21, 2019

@zzzeek For me do the changes for all your comment, is it OK for you, are the message good or should be improved?
Thanks in advance :-)

I might refactor some of the verbosity here but can you make the %s into %r for the orig_key , I think it's safer

@zzzeek
Copy link
Member

zzzeek commented Oct 21, 2019

like a function that can be reused in both


def _is_cache_miss(self, value, orig_key):
    if value is NO_VALUE:
        log.debug('Generate cache for key: %r', orig_key)
    elif value.metadata["v"] != value_version:
        log.debug('Update cache for key: %r', orig_key)
    elif self.region_invalidator.is_hard_invalidated(
            value.metadata["ct"]
    ):
        log.debug('Update hard invalidated cache for key: %r', orig_key)
    else:
        return True

    return False


if self._is_cache_miss(value, orig_key):
    raise NeedRegenerationException()

@sbrunner
Copy link
Contributor Author

@zzzeek Good improvement thanks => fixed :-)

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work to try to get revision b46bb31 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset b46bb31 added to existing Gerrit review https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work to try to get revision 693b6b0 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 693b6b0 added to existing Gerrit review https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528

When a cache is missing then we log the key to provide some useful informations to users.
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work to try to get revision 9e519cf of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 9e519cf added to existing Gerrit review https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528

@sbrunner
Copy link
Contributor Author

For me it's ready to be merge, thanks in advance :-)

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hervé Beraud (4383) wrote:

(1 comment)

Hello,

Some comments inline:

new_values = creator(*keys_to_get)
log.debug(
'Generate cache in %.2f s. for key: %r',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hervé Beraud (4383) wrote:

IMHO, I think it's most useful to print here the cache creation date and time instead of the used time to generate the cache.

This operation will surely only take just few miliseconds to generate this cache... In other words this information isn't reallly useful.

Also, I'm not sure, I do not have related benchmark, but I guess %.2f isn't enough to represent a quick treatment like this, possibly you will to only display "0.00 s" the most of the time.

As a user of this module I prefer know when my cache was created rather than the time used to generate it.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a slow query against a database or web service and can take any arbitrary amount of time, it could be minutes or any amount of time, which is useful to see in the logs as it would describe why a request is hanging. or if the async runner is used it can take minutes or hours while the app continues to run normally. dogpile.cache's use case is for optimizing data fetches that may be slow, it's the most important number to see in the logs really.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the log line will have the timestamp, so that's the time in which the finished value was created

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :)

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work to try to get revision 9e519cf of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 9e519cf added to existing Gerrit review https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mike bayer (zzzeek) wrote:

(1 comment)

log.debug(
'Generate cache in %.2f s. for key: %r',
time.time() - start_time, orig_key
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mike bayer (zzzeek) wrote:

creator is against keys_to_get here. I'll get this fixed up, thanks!

@sqla-tester
Copy link
Collaborator

mike bayer (zzzeek) wrote:

Okey doke, if one or both people reviewing this could come over to the gerrit, e.g. https://gerrit.sqlalchemy.org/#/c/sqlalchemy/dogpile.cache/+/1528/ , and look over the whole thing and try to find anything wrong, typos, something that won't work, etc., that would be great. I've run some demo scripts to see what the logging looks like and there's also some unit tests.

@sqla-tester
Copy link
Collaborator

Hervé Beraud (4383) wrote:

Code-Review+1

LGTM

@sqla-tester
Copy link
Collaborator

mike bayer (zzzeek) wrote:

Code-Review+2 Workflow+1

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/1528 has been merged. Congratulations! :)

@sbrunner
Copy link
Contributor Author

Thanks :-)

When do you plane to have a new release?
If not quickly, is it possible to have a dev release?

CU and Thanks in advance :-)

@sbrunner sbrunner deleted the add-cache-miss-logging branch October 28, 2019 16:33
@zzzeek
Copy link
Member

zzzeek commented Oct 28, 2019

it's released and note I am slowly starting to use semver on SQLAlchemy projects other than SQLAlchemy itself.

@sbrunner
Copy link
Contributor Author

Excellent, thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants