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

JdbcHelper urlTofactory Map replacement #1114

Merged
merged 3 commits into from
Feb 17, 2023
Merged

JdbcHelper urlTofactory Map replacement #1114

merged 3 commits into from
Feb 17, 2023

Conversation

jtduffy
Copy link
Contributor

@jtduffy jtduffy commented Jan 3, 2023

Replaces the existing ConcurrentHashMap used for the urlToFactory and urlToDatabaseName maps with a simple, custom cache that can expire items in the cache based on the last time an item was accessed.

The ConcurrentHashMap implementations were causing issues when used with MySql replication, where URLs to target replica databases were comprised of unique, generated Strings, causing the maps to grow without bound, which could eventually cause an OOM exception.

@jtduffy jtduffy marked this pull request as ready for review February 13, 2023 20:02

private final V wrappedValue;

private final Instant timeCreated;
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be longs?
it would save some allocation from the heap.

ExpiringValueLogicFunction expireLogicFunction) {
wrappedMap = new ConcurrentHashMap<>();

TimerTask task = new TimerTask() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use a static ScheduledThreadPoolExecutor?
Or else we'd be creating and holding one Thread per cache.

@jtduffy
Copy link
Contributor Author

jtduffy commented Feb 15, 2023

@meiao Comments addressed:

  • Instant -> long
  • static executor instance

Copy link
Contributor

@tbradellis tbradellis left a comment

Choose a reason for hiding this comment

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

+1 lgtm
I only have one question that is just for my own understanding. Was there a specific reason to implement this custom cache vs using the caffeine dependency we have? Or are we doing something with the timestamp value that isn't available in caffeine?

@meiao
Copy link
Contributor

meiao commented Feb 17, 2023

It is not trivial to use Caffeine in this module due to the way it is loaded to the JVM.

@jtduffy jtduffy merged commit 63b2cdc into main Feb 17, 2023
@jtduffy jtduffy deleted the jdbc-map-mem-leak branch February 17, 2023 18:27
toddwest pushed a commit to toddwest/newrelic-java-agent that referenced this pull request Feb 17, 2023
* WIP

* Refactoring of cache class; more tests

* Address PR comments: Instant --> long; static executor
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