Skip to content

Conversation

@faviansamatha
Copy link
Contributor

@faviansamatha faviansamatha commented Jan 30, 2026

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.

@faviansamatha faviansamatha force-pushed the fix/class-var-threads branch 3 times, most recently from 022dcaf to d0e922d Compare January 30, 2026 18:48
@faviansamatha faviansamatha marked this pull request as ready for review January 30, 2026 20:32
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,
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@karenc-bq karenc-bq changed the title Fix/class var threads fix: class var threads Jan 31, 2026
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.

2 participants