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)

Reply via email to