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

Improve/standardize rate limiting logic in Monitor #4894

Open
wants to merge 1 commit into
base: 2.1
Choose a base branch
from

Conversation

DomGarguilo
Copy link
Member

This PR uses Guavas Suppliers.memoizeWithExpiration() for caching, replacing the manual caching logic. This allows us to:

  • Remove synchronized from the get methods since Suppliers.memoizeWithExpiration() is thread safe
  • Remove the class-level maps that were previously being used for caching. Now, the fetch() methods that update the data, directly return the data instead of using these maps. These fetch() methods are called directly from the suppliers now.
  • Remove the age-off logic that was being done in the fetch() methods. It should be noted that the functionality has slightly changed. Since we just re-create a new map whenever the data is refreshed in the fetch() methods, there are no old values that need to be aged off.

@DomGarguilo DomGarguilo added this to the 2.1.4 milestone Sep 17, 2024
@DomGarguilo DomGarguilo self-assigned this Sep 17, 2024
Copy link
Contributor

@keith-turner keith-turner left a comment

Choose a reason for hiding this comment

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

Remove the age-off logic that was being done in the fetch() methods. It should be noted that the functionality has slightly changed. Since we just re-create a new map whenever the data is refreshed in the fetch() methods, there are no old values that need to be aged off.

That is a nice simplification.

@DomGarguilo
Copy link
Member Author

Remove the age-off logic that was being done in the fetch() methods. It should be noted that the functionality has slightly changed. Since we just re-create a new map whenever the data is refreshed in the fetch() methods, there are no old values that need to be aged off.

That is a nice simplification.

Yea definitely nice to be able to remove some code. Wasn't sure if this would be an issue though since before, the maps would contain values that would only be aged off after they were 15 minutes old. And now, since the data is recreated once every minute, all of the returned data will only ever be that old. Not too sure what the implications of this are or what the old values were being used for.

@keith-turner
Copy link
Contributor

Wasn't sure if this would be an issue though since before, the maps would contain values that would only be aged off after they were 15 minutes old.

I misread that code when I was reviewing. I thought they were aging off after 15 milliseconds, so did not think it was an issue. But its actually 15 minutes. It would be good to understand that change in behavior a bit better. So it seems like some things used to hang around for 15 minutes in the monitor display even after they were gone?

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.

Use common technique in monitor code to rate limit refreshing data
2 participants