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

Optimize thread locks and expiring cache for Enhanced Monitoring plugin #356

Merged
merged 8 commits into from
Feb 14, 2023

Conversation

sergiyvamz
Copy link
Contributor

Summary

Optimize thread locks and expiring cache for Enhanced Monitoring plugin.

Description

  • Expiring cache object has been replaced with CacheMap<>
  • AuroraTopologyService uses multiple caches that provides a better performance and concurrency.
  • Optimized work with monitoring context in Enhanced Monitoring plugin. A single queue with monitoring context is replaced with a two separate queues. The first queue holds all active context. When context monitoring time comes, the context is relocated to the second queue. Separating queues help to clear identify context that requires active node monitoring.
  • Performance optimization for various part of the code.

Additional Reviewers

@karenc-bq
@congoamz

expiring cache
verify cluster status before each test
increase session token expiration time
// Check for min delay between node health check
if (delayMillis < MIN_CONNECTION_CHECK_TIMEOUT_MILLIS) {
delayMillis = MIN_CONNECTION_CHECK_TIMEOUT_MILLIS;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should the elapsedTime subtraction come after this reset to the MIN_CONNECTION timeout? For example, if we spent 1s on the status check and the MIN_CONNECTION timeout is 3s, we only have to wait 2s

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 was thinking about this scenario but I guess it makes sense to avoid checking node status too often. So MIN_CONNECTION is applied to delayMillis.

@sergiyvamz sergiyvamz changed the title [WIP] Optimize thread locks and expiring cache for Enhanced Monitoring plugin Optimize thread locks and expiring cache for Enhanced Monitoring plugin Feb 3, 2023
Comment on lines +49 to +59
CacheItem<V> cacheItem = cache.computeIfPresent(key, (kk, vv) -> vv.isExpired() ? null : vv);
return cacheItem == null ? null : cacheItem.item;
}

public V get(final K key, final V defaultItemValue, long itemExpirationNano) {
CacheItem<V> cacheItem = cache.compute(key,
(kk, vv) -> (vv == null || vv.isExpired())
? new CacheItem<>(defaultItemValue, System.nanoTime() + itemExpirationNano)
: vv);
return cacheItem.item;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these methods can be simplified if you add a getter for cacheItem.item:

  public V getItem() {
      return isExpired() ? null : item;
    }

@sergiyvamz sergiyvamz merged commit 9818aad into main Feb 14, 2023
@sergiyvamz sergiyvamz deleted the efm-performance branch February 14, 2023 00:03
@karenc-bq
Copy link
Contributor

This PR address #333

sergiyvamz pushed a commit to aws/aws-advanced-jdbc-wrapper that referenced this pull request Mar 20, 2023
Porting over optimizations from the aws-mysql-jdbc driver:
awslabs/aws-mysql-jdbc#356 

### By submitting this pull request, I confirm that my contribution is
made under the terms of the Apache 2.0 license.

---------

Co-authored-by: Aaron Congo <[email protected]>
Co-authored-by: sergiyv-bitquill <[email protected]>
@YoungHu
Copy link

YoungHu commented Jun 3, 2023

this fix have bug will case #412

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.

5 participants