dimitarndimitrov commented on code in PR #17184:
URL: https://github.com/apache/kafka/pull/17184#discussion_r1763330333


##########
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/metrics/HistogramBenchmark.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.jmh.metrics;
+
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.kafka.coordinator.group.metrics.HdrHistogram;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import com.yammer.metrics.core.Histogram;
+import com.yammer.metrics.core.MetricName;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Group;
+import org.openjdk.jmh.annotations.GroupThreads;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Benchmark)
+@Fork(value = 1)
+@Threads(10)
+@Warmup(iterations = 5)
+@Measurement(iterations = 5)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+public class HistogramBenchmark {
+
+    /*
+     * This benchmark compares the performance of the most commonly used in 
the Kafka codebase
+     * Yammer histograms and HdrHistogram. It does it by focusing on the write 
path in a multiple
+     * writers, multiple readers scenario.
+     *
+     * The benchmark relies on JMH Groups which allows us to distribute the 
number of worker threads
+     * to the different benchmark methods.
+     */
+
+    private static final long MAX_VALUE = TimeUnit.MINUTES.toMillis(1L);
+
+    private volatile Histogram yammerHistogram;
+    private volatile HdrHistogram hdrHistogram;
+
+    @Setup(Level.Trial)
+    public void setUp() {
+        yammerHistogram = 
KafkaYammerMetrics.defaultRegistry().newHistogram(new MetricName("a", "", ""), 
true);
+        hdrHistogram = new HdrHistogram(MAX_VALUE, 3);
+    }
+
+    /*
+     * The write benchmark methods below are the core of the benchmark. They 
use ThreadLocalRandom
+     * to generate values to record. This is much faster than the actual 
histogram recording, so
+     * the benchmark results are representative of the histogram 
implementation.
+     */
+
+    @Benchmark
+    @Group("runner")
+    @GroupThreads(3)
+    public void write_YammerHistogram() {

Review Comment:
   In some, but apparently not in the ones in AK, so I'll fix this (e.g. making 
this `writeYammerHistogram`). 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to