-
Notifications
You must be signed in to change notification settings - Fork 17
fix: class var threads #1090
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
base: main
Are you sure you want to change the base?
fix: class var threads #1090
Conversation
022dcaf to
d0e922d
Compare
d0e922d to
95534b1
Compare
| WrapperProperties.CLUSTER_TOPOLOGY_HIGH_REFRESH_RATE_MS.get_int(self._props) * 1_000_000) | ||
|
|
||
| self._monitors = SlidingExpirationCacheContainer.get_or_create_cache( | ||
| name=self._MONITOR_CACHE_NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to treat these monitor cache names as class var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question for the cleanup nanos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should treat them as class variables. As a "single source of truth", since we don't want anything else that uses the classes to have different configurations.
| def release_resources(): | ||
| MonitoringRdsHostListProvider._monitors.clear() | ||
| # Note: Monitors are now managed by SlidingExpirationCacheContainer | ||
| # and will be cleaned up via cleanup.release_resources() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we log a deprecation message here and tell users to switch to
from aws_advanced_python_wrapper import AwsWrapperConnection, release_resources
aws_advanced_python_wrapper .release_resources()instead? if they are not already calling that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up deleting it as this wasn't released yet, and we only used it inside our integration tests.
Description
Previously, any class variables with SlidingExpirationCacheWithCleanupThreads will automatically be initialized when anything in that file is imported. This means that even if users don't use plugins that require this, we would be spawning 5 threads for other classes. This is not ideal.
This PR containerizes replaces all SlidingExpirationCacheWithCleanupThreads with SlidingExpirationCache. In this container, we will run only 1 thread that will cleanup all these caches every 5 minutes. This thread will not be spawned until the first time we make a pool.
Furthermore this optimizes instances that uses ThreadPoolContainer by just storing a reference to the ThreadPool that the class uses. This is an improvement because anytime a class uses a thread pool container, it would not have to fight for the lock.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.