![](/img/trans.png)
[英]Are Kafka Streams Appropriate for Triggering Batch Processing of Records?
[英]Batch Size Problem with MapR Streams Kafka API
您好,我正在使用 Kafka MapRStream 從 Mapr Streams 主題接收事件。
我正在嘗試增加我的消費者的批量大小,但我在一批中沒有收到超過30 條消息!
單個事件的大小約為 5000 字節。 如果事件較小,我會在一批中獲得更多。
這是我對消費者的配置:
public static void main( String[] args ) {
final Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "batchSize");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, 50000);
props.put(ConsumerConfig.RECEIVE_BUFFER_CONFIG, 26214400);
props.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, 100 * 1024 * 1024);
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1000);
Consumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList(TOPIC));
long totalCount = 0;
long start = System.currentTimeMillis();
long countTimesNoMessages = 0;
while (countTimesNoMessages < 10) {
ConsumerRecords<String, String> records = consumer.poll(1000);
totalCount += records.count();
System.out.println(records.count());
if (records.count() == 0) {
countTimesNoMessages++;
}
}
long end = System.currentTimeMillis();
System.out.println((end - start) + " for " + totalCount + " messages");
}
這些是可能的配置點。
https://mapr.com/docs/61/MapR_Streams/configuration-parameters.html
請注意, fetch.max.bytes
是所有分區的總最大值和sum(max.partition.fetch.bytes)
不能超過 fetch.max.bytes。
調整max.partition.fetch.bytes
是正常的,因此每個分區輪詢超過 64Kb(默認),並且還會調整fetch.max.bytes
以便它允許max.partition.fetch.bytes
正常工作。
您不應該將批量大小設置得太大。 一旦輪詢流的請求頻率降至每秒幾百以下,您就不太可能獲得額外的性能改進,並且更有可能在線程失敗時遇到熱點問題或大量重做工作.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.