junrao commented on code in PR #13391: URL: https://github.com/apache/kafka/pull/13391#discussion_r1164392731
########## core/src/main/scala/kafka/server/KafkaRequestHandler.scala: ########## @@ -69,20 +108,52 @@ class KafkaRequestHandler(id: Int, completeShutdown() return + case callback: RequestChannel.CallbackRequest => + try { + val originalRequest = callback.originalRequest + + // If we've already executed a callback for this request, reset the times and subtract the callback time from the + // new dequeue time. This will allow calculation of multiple callback times. + // Otherwise, set dequeue time to now. + if (originalRequest.callbackRequestDequeueTimeNanos.isDefined) { + val prevCallbacksTimeNanos = originalRequest.callbackRequestCompleteTimeNanos.getOrElse(0L) - originalRequest.callbackRequestDequeueTimeNanos.getOrElse(0L) + originalRequest.callbackRequestCompleteTimeNanos = None + originalRequest.callbackRequestDequeueTimeNanos = Some(time.nanoseconds() - prevCallbacksTimeNanos) + } else { + originalRequest.callbackRequestDequeueTimeNanos = Some(time.nanoseconds()) + } + + currentRequest.set(originalRequest) + callback.fun() + if (originalRequest.callbackRequestCompleteTimeNanos.isEmpty) Review Comment: Thanks for the explanation. I understand it now. callbackRequestCompleteTimeNanos can be non-empty if the response is sent before the callback completes. Currently, we update the metric when the sending of the response completes. So, a more accurate place to set callbackRequestCompleteTimeNanos in RequestChannel is when the response send completes. An alternative approach is to delay the updating of the request time metrics until the callback completes. This simplifies the setting of callbackRequestCompleteTimeNanos since it only needs to be done in KafkaRequestHandler and is more accurate since we don't need to cut off callbackRequestCompleteTimeNanos by response send complete time. Both of these could be addressed in a followup jira. -- 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