Improve metrics interceptor performance; avoid MetricID creations - 2.x #1602
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1595
The existing metrics annotation interceptor creates a new
MetricID
each time an intercepted method is invoked, in order to help locate the relevant metric to update. This is expensive because theMetricID
constructor consults config to look for global tags and an app identifier tag.This PR avoids the expense of creating all those
MetricID
objects by:MetricID
to gather the global and app tags.Element
with the metric instance to be updated when that element is intercepted. On the first intercepted call for an element, the revised code:Registry
all metric IDs that share the same metric name.Assumptions/possible issues:
Element
is the correct unique identifier to use in the map to relevant metric. This seems right; remember that each metric type has its own map.MetricID
created when theInterceptor
is instantiated is OK. Because config is not dynamic, this should be fine and the global and app tags obtained via config would not change as the app runs. The harvested tags should match the global and app tags in anyMetricID
created at any time during the app's lifetime.public
one existing package-private method on ourRegistry
implementation class in the SEmetrics
project. This does increase the exposed surface area of ourRegistry
but users should be usingMetricRegistry
and notRegistry
directly anyway. Also, using the newly-exposed method helps to streamline the code that locates and caches the metric associated with an interception point on the first usage.Our tests and the TCK pass.
In informal experience with a new unit test, the time to execute 10,000 calls to an intercepted site dropped from 1.25 s to about .06 - .08 s.