Improve metrics interceptor performance; avoid MetricID creations - 2.x (#1602)

* For performance, avoid creating MetricID instances repeatedly when looking up the metric associated with each call to an intercepted call; instead, cache the metric with each annotation site
This commit is contained in:
Tim Quinn
2020-03-31 15:36:55 -05:00
committed by GitHub
parent 49dd04d004
commit ab648141a3
9 changed files with 206 additions and 35 deletions

View File

@@ -473,7 +473,7 @@ public final class MetricsSupport implements Service {
.ifPresentOrElse(entry -> {
if (req.headers().isAccepted(MediaType.APPLICATION_JSON)) {
JsonObjectBuilder builder = JSON.createObjectBuilder();
entry.getKey().jsonMeta(builder, entry.getValue());
HelidonMetric.class.cast(entry.getKey()).jsonMeta(builder, entry.getValue());
res.send(builder.build());
} else {
res.status(Http.Status.NOT_ACCEPTABLE_406);

View File

@@ -523,7 +523,7 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
* @param metricName The metric name.
* @return Optional map entry..
*/
synchronized Optional<Map.Entry<HelidonMetric, List<MetricID>>> getOptionalMetricWithIDsEntry(String metricName) {
public synchronized Optional<Map.Entry<? extends Metric, List<MetricID>>> getOptionalMetricWithIDsEntry(String metricName) {
final List<MetricID> metricIDs = allMetricIDsByName.get(metricName);
if (metricIDs == null || metricIDs.isEmpty()) {
return Optional.empty();