[
https://issues.apache.org/jira/browse/KAFKA-7295?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16596482#comment-16596482
]
ASF GitHub Bot commented on KAFKA-7295:
---------------------------------------
lindong28 closed pull request #5508: KAFKA-7295; Fix
RequestHandlerAvgIdlePercent metric calculation
URL: https://github.com/apache/kafka/pull/5508
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/core/src/main/scala/kafka/server/KafkaRequestHandler.scala
b/core/src/main/scala/kafka/server/KafkaRequestHandler.scala
index d0d41219663..e0f14e97299 100755
--- a/core/src/main/scala/kafka/server/KafkaRequestHandler.scala
+++ b/core/src/main/scala/kafka/server/KafkaRequestHandler.scala
@@ -23,7 +23,7 @@ import kafka.metrics.KafkaMetricsGroup
import java.util.concurrent.{CountDownLatch, TimeUnit}
import java.util.concurrent.atomic.AtomicInteger
-import com.yammer.metrics.core.Meter
+import com.yammer.metrics.core.{Meter, Histogram}
import org.apache.kafka.common.internals.FatalExitError
import org.apache.kafka.common.utils.{KafkaThread, Time}
@@ -35,6 +35,7 @@ import scala.collection.mutable
class KafkaRequestHandler(id: Int,
brokerId: Int,
val aggregateIdleMeter: Meter,
+ val aggregateIdlePercent: Histogram,
val totalHandlerThreads: AtomicInteger,
val requestChannel: RequestChannel,
apis: KafkaApis,
@@ -52,9 +53,7 @@ class KafkaRequestHandler(id: Int,
val startSelectTime = time.nanoseconds
val req = requestChannel.receiveRequest(300)
- val endTime = time.nanoseconds
- val idleTime = endTime - startSelectTime
- aggregateIdleMeter.mark(idleTime / totalHandlerThreads.get)
+ val endSelectTime = time.nanoseconds
req match {
case RequestChannel.ShutdownRequest =>
@@ -64,7 +63,7 @@ class KafkaRequestHandler(id: Int,
case request: RequestChannel.Request =>
try {
- request.requestDequeueTimeNanos = endTime
+ request.requestDequeueTimeNanos = endSelectTime
trace(s"Kafka request handler $id on broker $brokerId handling
request $request")
apis.handle(request)
} catch {
@@ -78,6 +77,13 @@ class KafkaRequestHandler(id: Int,
case null => // continue
}
+
+ val endExecutionTime = time.nanoseconds
+ val idleTime = endSelectTime - startSelectTime
+ val idlePercent = idleTime * 100 / (endExecutionTime - startSelectTime)
+
+ aggregateIdleMeter.mark(idleTime / totalHandlerThreads.get)
+ aggregateIdlePercent.update(idlePercent)
}
shutdownComplete.countDown()
}
@@ -99,8 +105,10 @@ class KafkaRequestHandlerPool(val brokerId: Int,
numThreads: Int) extends Logging with
KafkaMetricsGroup {
private val threadPoolSize: AtomicInteger = new AtomicInteger(numThreads)
- /* a meter to track the average free capacity of the request handlers */
+ // To remove in 2.2
private val aggregateIdleMeter = newMeter("RequestHandlerAvgIdlePercent",
"percent", TimeUnit.NANOSECONDS)
+ /* a meter to track the average free capacity of the request handlers */
+ private val aggregateIdlePercent = newHistogram("RequestHandlerIdlePercent")
this.logIdent = "[Kafka Request Handler on Broker " + brokerId + "], "
val runnables = new mutable.ArrayBuffer[KafkaRequestHandler](numThreads)
@@ -109,7 +117,7 @@ class KafkaRequestHandlerPool(val brokerId: Int,
}
def createHandler(id: Int): Unit = synchronized {
- runnables += new KafkaRequestHandler(id, brokerId, aggregateIdleMeter,
threadPoolSize, requestChannel, apis, time)
+ runnables += new KafkaRequestHandler(id, brokerId, aggregateIdleMeter,
aggregateIdlePercent, threadPoolSize, requestChannel, apis, time)
KafkaThread.daemon("kafka-request-handler-" + id, runnables(id)).start()
}
diff --git a/docs/upgrade.html b/docs/upgrade.html
index 979190db7b7..138e1d45854 100644
--- a/docs/upgrade.html
+++ b/docs/upgrade.html
@@ -19,6 +19,7 @@
<script id="upgrade-template" type="text/x-handlebars-template">
+
<h4><a id="upgrade_2_1_0" href="#upgrade_2_1_0">Upgrading from 0.8.x, 0.9.x,
0.10.0.x, 0.10.1.x, 0.10.2.x, 0.11.0.x, 1.0.x, 1.1.x, or 2.0.0 to 2.1.0</a></h4>
<p><b>Additional Upgrade Notes:</b></p>
@@ -41,6 +42,10 @@ <h4><a id="upgrade_2_1_0" href="#upgrade_2_1_0">Upgrading
from 0.8.x, 0.9.x, 0.1
Even though the old <code>Describe Cluster</code> access is still
supported for backward compatibility, using it for this API is not advised.</li>
</ol>
+<h5><a id="upgrade_2_1_0_notable" href="#upgrade_2_1_0_notable">Notable
changes in 2.1.0</a></h5>
+<ul>
+ <li>TBD</li>
+</ul>
<h4><a id="upgrade_2_0_0" href="#upgrade_2_0_0">Upgrading from 0.8.x, 0.9.x,
0.10.0.x, 0.10.1.x, 0.10.2.x, 0.11.0.x, 1.0.x, or 1.1.x to 2.0.0</a></h4>
<p>Kafka 2.0.0 introduces wire protocol changes. By following the recommended
rolling upgrade plan below,
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Fix RequestHandlerAvgIdlePercent metric calculation
> ---------------------------------------------------
>
> Key: KAFKA-7295
> URL: https://issues.apache.org/jira/browse/KAFKA-7295
> Project: Kafka
> Issue Type: Improvement
> Reporter: Dong Lin
> Assignee: Dong Lin
> Priority: Major
>
> Currently the RequestHandlerAvgIdlePercent metric may be larger than 1 due to
> the way it is calculated. This is counter-intuitive since by definition it is
> supposed to be a percentage metric and its value should be in range [0, 1]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)