You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/07/19 02:48:26 UTC
[james-project] 03/03: [PERFORMANCE] DropWizardMetricFactory:
optimize wrapping monos
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3ac9f33a9ebf1b19f8b6c7fac0e799c04f117873
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jul 15 11:40:50 2021 +0700
[PERFORMANCE] DropWizardMetricFactory: optimize wrapping monos
Wrapping monos with a flux is sub-optimal as it leads to cancels being
repeatedly called and takes as much as 2% of applicative CPU.
---
.../apache/james/metrics/dropwizard/DropWizardMetricFactory.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
index 2daf91a..54962b8 100644
--- a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
+++ b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -38,6 +38,7 @@ import com.codahale.metrics.Timer;
import com.codahale.metrics.jmx.JmxReporter;
import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
public class DropWizardMetricFactory implements MetricFactory, Startable {
@@ -64,6 +65,11 @@ public class DropWizardMetricFactory implements MetricFactory, Startable {
@Override
public <T> Publisher<T> decoratePublisherWithTimerMetric(String name, Publisher<T> publisher) {
+ if (publisher instanceof Mono) {
+ return Mono.using(() -> timer(name),
+ any -> Mono.from(publisher),
+ DropWizardTimeMetric::stopAndPublish);
+ }
return Flux.using(() -> timer(name),
any -> publisher,
DropWizardTimeMetric::stopAndPublish);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org