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/16 13:07:00 UTC

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

     [ https://issues.apache.org/jira/browse/KAFKA-18990?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Chia-Ping Tsai resolved KAFKA-18990.
------------------------------------
    Fix Version/s: 4.1.0
       Resolution: Fixed

> 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: Ming-Yen Chung
>            Priority: Major
>             Fix For: 4.1.0
>
>
> 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)