anjy7 commented on code in PR #22669:
URL: https://github.com/apache/kafka/pull/22669#discussion_r3484069959


##########
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/raft/LeaderBenchmark.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.raft;
+
+import org.apache.kafka.raft.RaftClientBenchmarkContext;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+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.Warmup;
+
+import java.util.concurrent.TimeUnit;
+
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Warmup(iterations = 5)
+@Measurement(iterations = 10)
+@Fork(3)
+public class LeaderBenchmark {
+    private static final int LOCAL_ID = 0;
+    private static final int VOTER_COUNT = 3;
+
+    private RaftClientBenchmarkContext context;
+
+    @Setup(Level.Trial)
+    public void setup() throws Exception {
+        context = RaftClientBenchmarkContext.leader(LOCAL_ID, VOTER_COUNT);
+        context.advanceLeaderHwmToLogEnd();
+        context.resetCounters();
+    }
+
+    /**
+     * Leader handles a valid FETCH from a fully caught-up follower (fetch 
offset == log end offset),
+     * which does not advance the high watermark — the steady-state 
heartbeat-style fetch.
+     */
+    @Benchmark
+    public void leaderHandleFetch(ProtocolCounters counters) throws Exception {
+        int epoch = context.currentEpoch();
+        long endOffset = context.logEndOffset();
+        context.deliverRequest(context.fetchRequest(epoch, 
context.otherVoter(), endOffset, epoch, 0));
+        context.pollUntilResponse();
+
+        counters.drainFrom(context);

Review Comment:
   I looked into this and it runs into a couple of JMH constraints that I don't 
think we can get around cleanly, even with the other changes. 
   
   The blocker is @AuxCounters. `drainFrom` does two things every invocation: 
accumulates the work deltas and increments operations (the per-op divisor). To 
move the drain into a @TearDown, the counters @State has to be a parameter of 
that teardown  but JMH won't let the same @AuxCounters state be injected into 
both the @Benchmark and a @TearDown (it fails compilation with "Conflicting 
@AuxCounters counters"). 
   
   I think it's okay to leave it because drainFrom is a fixed, cost is applied 
identically on trunk and on the refactor branch (whenever the comparison will 
be done before/after the refactor).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to