soarez commented on code in PR #15622:
URL: https://github.com/apache/kafka/pull/15622#discussion_r1883003172
##########
server/src/main/java/org/apache/kafka/server/config/KRaftConfigs.java:
##########
@@ -114,6 +114,10 @@ public class KRaftConfigs {
public static final String SERVER_MAX_STARTUP_TIME_MS_DOC = "The maximum
number of milliseconds we will wait for the server to come up. " +
"By default there is no limit. This should be used for testing
only.";
+ public static final String MIN_SLOW_EVENT_TIME_MS_CONFIG =
"controller.slow.event.min.ms";
+ public static final int MIN_SLOW_EVENT_TIME_MS_DEFAULT = 200;
+ public static final String MIN_SLOW_EVENT_TIME_MS_DOC = "Do not log slow
controller events which are slowed than this duration.";
Review Comment:
```suggestion
public static final String MIN_SLOW_EVENT_TIME_MS_DOC = "Do not log slow
controller events which are slower than this duration.";
```
Something like this could be a bit easier to understand:
> Log controller events take longer than this duration.
I'd also add reference the P99 threshold, e.g.
> Log controller events with a 30 second P99 duration that is longer than
this minimum.
##########
metadata/src/main/java/org/apache/kafka/controller/SlowEventsLogger.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.controller;
+
+import org.apache.kafka.common.utils.LogContext;
+
+import org.slf4j.Logger;
+
+import java.util.function.Supplier;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+/**
+ * Track the p99 for controller event queue processing time. If we encounter
an event that takes longer
+ * than this cached p99 time, we will log it at INFO level on the controller
logger.
+ */
+public class SlowEventsLogger {
+ /**
+ * Don't report any p99 events below this threshold. This prevents the
controller from reporting p99 event
+ * times in the idle case where p99 event times are essentially the
average as well.
+ */
+ private final long minSlowEventTimeNs;
+
+ /**
+ * Function that returns the current p99 time in millis. This call can be
expensive, and since the histogram is
+ * biased towards the last 5 minutes of data, we only need to update this
p99 every so often.
+ */
+ private final Supplier<Double> thresholdMsSupplier;
+
+ private final Logger log;
+
+ /**
+ * The current p99 threshold in nanos.
+ */
+ private long thresholdNs;
+
+ public SlowEventsLogger(
+ int minSlowEventTimeMs,
+ Supplier<Double> thresholdMsSupplier,
+ LogContext logContext
+ ) {
+ this.minSlowEventTimeNs = MILLISECONDS.toNanos(minSlowEventTimeMs);
+ this.thresholdMsSupplier = thresholdMsSupplier;
+ this.thresholdNs = minSlowEventTimeMs;
+ this.log = logContext.logger(SlowEventsLogger.class);
+ }
+
+ /**
+ * Produce an INFO log if the given event ran for longer than the current
p99 event processing time.
Review Comment:
```suggestion
* Produce an INFO log if the given event ran for at least as long as
the current p99 event processing time.
```
##########
metadata/src/main/java/org/apache/kafka/controller/SlowEventsLogger.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.controller;
+
+import org.apache.kafka.common.utils.LogContext;
+
+import org.slf4j.Logger;
+
+import java.util.function.Supplier;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+/**
+ * Track the p99 for controller event queue processing time. If we encounter
an event that takes longer
+ * than this cached p99 time, we will log it at INFO level on the controller
logger.
+ */
+public class SlowEventsLogger {
+ /**
+ * Don't report any p99 events below this threshold. This prevents the
controller from reporting p99 event
+ * times in the idle case where p99 event times are essentially the
average as well.
+ */
+ private final long minSlowEventTimeNs;
+
+ /**
+ * Function that returns the current p99 time in millis. This call can be
expensive, and since the histogram is
+ * biased towards the last 5 minutes of data, we only need to update this
p99 every so often.
+ */
+ private final Supplier<Double> thresholdMsSupplier;
+
+ private final Logger log;
+
+ /**
+ * The current p99 threshold in nanos.
+ */
+ private long thresholdNs;
+
+ public SlowEventsLogger(
+ int minSlowEventTimeMs,
+ Supplier<Double> thresholdMsSupplier,
+ LogContext logContext
+ ) {
+ this.minSlowEventTimeNs = MILLISECONDS.toNanos(minSlowEventTimeMs);
+ this.thresholdMsSupplier = thresholdMsSupplier;
+ this.thresholdNs = minSlowEventTimeMs;
+ this.log = logContext.logger(SlowEventsLogger.class);
+ }
+
+ /**
+ * Produce an INFO log if the given event ran for longer than the current
p99 event processing time.
+ *
+ * @return true if a slow event was logged, false otherwise.
+ */
+ public boolean maybeLogEvent(String name, long durationNs) {
+ if (durationNs >= minSlowEventTimeNs && durationNs >= thresholdNs) {
+ log.info("Slow controller event {} processed in {} us which is
greater than p99 of {} us",
Review Comment:
```suggestion
log.info("Slow controller event {} processed in {} us which is
longer or equal to p99 of {} us",
```
##########
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##########
@@ -175,16 +175,21 @@
*/
public final class QuorumController implements Controller {
/**
- * The maximum records that the controller will write in a single batch.
+ * The default maximum records that the controller will write in a single
batch.
*/
- private static final int MAX_RECORDS_PER_BATCH = 10000;
+ private static final int DEFAULT_MAX_RECORDS_PER_BATCH = 10000;
Review Comment:
Even though there are no code paths that change the value, within the scope
of `QuorumController.Builder` this is in fact a default.
##########
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##########
@@ -1587,7 +1603,7 @@ private QuorumController(
}
registerElectUnclean(TimeUnit.MILLISECONDS.toNanos(uncleanLeaderElectionCheckIntervalMs));
registerExpireDelegationTokens(MILLISECONDS.toNanos(delegationTokenExpiryCheckIntervalMs));
-
+ registerUpdateSlowEventLogger(MILLISECONDS.toNanos(30000));
Review Comment:
```suggestion
registerUpdateSlowEventLogger(SECONDS.toNanos(30));
```
##########
metadata/src/main/java/org/apache/kafka/controller/SlowEventsLogger.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.controller;
+
+import org.apache.kafka.common.utils.LogContext;
+
+import org.slf4j.Logger;
+
+import java.util.function.Supplier;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+/**
+ * Track the p99 for controller event queue processing time. If we encounter
an event that takes longer
+ * than this cached p99 time, we will log it at INFO level on the controller
logger.
+ */
+public class SlowEventsLogger {
+ /**
+ * Don't report any p99 events below this threshold. This prevents the
controller from reporting p99 event
+ * times in the idle case where p99 event times are essentially the
average as well.
+ */
+ private final long minSlowEventTimeNs;
+
+ /**
+ * Function that returns the current p99 time in millis. This call can be
expensive, and since the histogram is
+ * biased towards the last 5 minutes of data, we only need to update this
p99 every so often.
+ */
+ private final Supplier<Double> thresholdMsSupplier;
+
+ private final Logger log;
+
+ /**
+ * The current p99 threshold in nanos.
+ */
+ private long thresholdNs;
+
+ public SlowEventsLogger(
+ int minSlowEventTimeMs,
+ Supplier<Double> thresholdMsSupplier,
+ LogContext logContext
+ ) {
+ this.minSlowEventTimeNs = MILLISECONDS.toNanos(minSlowEventTimeMs);
+ this.thresholdMsSupplier = thresholdMsSupplier;
+ this.thresholdNs = minSlowEventTimeMs;
+ this.log = logContext.logger(SlowEventsLogger.class);
+ }
+
+ /**
+ * Produce an INFO log if the given event ran for longer than the current
p99 event processing time.
+ *
+ * @return true if a slow event was logged, false otherwise.
+ */
+ public boolean maybeLogEvent(String name, long durationNs) {
+ if (durationNs >= minSlowEventTimeNs && durationNs >= thresholdNs) {
+ log.info("Slow controller event {} processed in {} us which is
greater than p99 of {} us",
+ name,
+ NANOSECONDS.toMicros(durationNs),
+ NANOSECONDS.toMicros(thresholdNs)
+ );
+ return true;
+ } else if (durationNs >= thresholdNs) {
+ return false;
+ }
+ return false;
Review Comment:
```suggestion
}
return false;
```
--
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]