chia7712 commented on code in PR #13215: URL: https://github.com/apache/kafka/pull/13215#discussion_r3927390720
########## tools/src/main/java/org/apache/kafka/tools/ConsumerPerformance.java: ########## @@ -0,0 +1,407 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.tools; + +import joptsimple.OptionException; +import joptsimple.OptionSpec; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.common.Metric; +import org.apache.kafka.common.MetricName; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.serialization.ByteArrayDeserializer; +import org.apache.kafka.common.utils.Exit; +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.server.util.CommandDefaultOptions; +import org.apache.kafka.server.util.CommandLineUtils; +import org.apache.kafka.server.util.ToolsUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Properties; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +import static joptsimple.util.RegexMatcher.regex; + +public class ConsumerPerformance { + private static final Logger LOG = LoggerFactory.getLogger(ConsumerPerformance.class); + private static final Random RND = new Random(); + + public static void main(String[] args) { + try { + LOG.info("Starting consumer..."); + ConsumerPerfOptions options = new ConsumerPerfOptions(args); + AtomicLong totalMessagesRead = new AtomicLong(0); + AtomicLong totalBytesRead = new AtomicLong(0); + AtomicLong joinTimeMs = new AtomicLong(0); + AtomicLong joinTimeMsInSingleRound = new AtomicLong(0); + + if (!options.hideHeader()) + printHeader(options.showDetailedStats()); + + KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(options.props()); + long bytesRead = 0L; Review Comment: These local variables are only used in consume, so we could declare them there instead. We will file a patch to address it -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
