You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Chia-Ping Tsai (Jira)" <ji...@apache.org> on 2025/03/14 20:16:00 UTC

[jira] [Created] (KAFKA-18990) Optimize BaseQuotaTest#produceUntilThrottled to avoid redundant MetricName creation

Chia-Ping Tsai created KAFKA-18990:
--------------------------------------

             Summary: Optimize BaseQuotaTest#produceUntilThrottled to avoid redundant MetricName creation
                 Key: KAFKA-18990
                 URL: https://issues.apache.org/jira/browse/KAFKA-18990
             Project: Kafka
          Issue Type: Improvement
            Reporter: Chia-Ping Tsai
            Assignee: Chia-Ping Tsai


reference: https://github.com/apache/kafka/blob/trunk/core/src/test/scala/integration/kafka/api/BaseQuotaTest.scala#L229


{code:java}
  def produceUntilThrottled(maxRecords: Int, waitForRequestCompletion: Boolean = true): Int = {
    var numProduced = 0
    var throttled = false
    do {
      val payload = numProduced.toString.getBytes
      val future = producer.send(new ProducerRecord[Array[Byte], Array[Byte]](topic, null, null, payload),
        new ErrorLoggingCallback(topic, null, null, true))
      numProduced += 1
      do {
        // move this out of loop
        val metric = throttleMetric(QuotaType.PRODUCE, producerClientId)
        throttled = metric != null && metricValue(metric) > 0
      } while (!future.isDone && (!throttled || waitForRequestCompletion))
    } while (numProduced < maxRecords && !throttled)
    numProduced
  }
{code}




--
This message was sent by Atlassian Jira
(v8.20.10#820010)