0Pricing
Apache Kafka & Stream Processing Fundamentals · Aula

Agrupamento, compressão e ajuste de linger.ms

Aprenda como o agrupamento de mensagens do produtor, linger.ms e a compressão interagem para trocar latência por vazão e reduzir o uso de rede e disco.

Agrupamento, compressão e ajuste de linger.ms é uma aula grátis de Apache Kafka & Stream Processing Fundamentals no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Apache Kafka & Stream Processing Fundamentals, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Apache Kafka & Stream Processing Fundamentals inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

The Throughput Lever

Sending one record per network call is slow. Kafka producers batch records per partition before sending, amortizing overhead and dramatically raising throughput.

batch.size

batch.size sets the maximum size (in bytes) of a single batch per partition.

  • Larger batches = better throughput, more memory.
  • A batch is sent when it fills or when linger expires.
// 64 KB batches
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 65536);

linger.ms

linger.ms tells the producer to wait a short time for more records before sending, even if the batch isn't full.

  • 0 (default) = send as soon as possible, lowest latency.
  • A few ms = bigger batches, higher throughput.
props.put(ProducerConfig.LINGER_MS_CONFIG, 10);

How They Interact

Think of it as fill or wait:

  • The batch ships when it reaches batch.size.
  • Or when linger.ms elapses, whichever comes first.

Raising both increases batch sizes at the cost of latency.

Compression Basics

compression.type compresses each batch before it goes over the wire and to disk.

Bigger batches compress better, so compression pairs naturally with linger tuning.

props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "lz4");

Choosing a Codec

Common codecs and their trade-offs:

  • lz4 — fast, good ratio, popular default.
  • snappy — very fast, lower ratio.
  • zstd — best ratio, slightly more CPU.
  • gzip — high ratio, higher CPU.

End-to-End Compression

Kafka stores batches compressed and serves them compressed; consumers decompress.

This means compression saves network, disk, and replication bandwidth — not just the producer link.

buffer.memory

buffer.memory caps total memory for unsent records.

If batches accumulate faster than they ship, the producer blocks (up to max.block.ms) — a sign brokers can't keep up or batching is too aggressive.

props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);

A High-Throughput Profile

A typical throughput-oriented configuration:

props.put(ProducerConfig.BATCH_SIZE_CONFIG, 131072);
props.put(ProducerConfig.LINGER_MS_CONFIG, 20);
props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "zstd");
props.put(ProducerConfig.ACKS_CONFIG, "all");

Latency vs. Throughput

There is no free lunch:

  • Lower linger.ms and smaller batches = lower latency.
  • Higher values + compression = higher throughput, more latency.

Tune to your SLA, then measure.

Measuring the Effect

Watch producer JMX metrics to confirm tuning works:

  • batch-size-avg — are batches actually larger?
  • compression-rate-avg — how well does data compress?
  • record-queue-time-avg — added latency from linger.

Quick Check

Test your understanding of batching and linger.

Recap

You learned producer batching and compression tuning.

  • batch.size + linger.ms control batch size and the latency trade-off.
  • Compression (lz4/zstd) saves network, disk, and replication bandwidth.
  • buffer.memory bounds in-flight data.
  • Verify with batch-size-avg and compression-rate-avg metrics.

Perguntas Frequentes

A aula “Agrupamento, compressão e ajuste de linger.ms” é grátis?

Sim — o texto completo de “Agrupamento, compressão e ajuste de linger.ms” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Apache Kafka & Stream Processing Fundamentals, atualize para CoddyKit PRO. O curso de Apache Kafka & Stream Processing Fundamentals inclui 4 aulas no total.

O que vou aprender em “Agrupamento, compressão e ajuste de linger.ms”?

Aprenda como o agrupamento de mensagens do produtor, linger.ms e a compressão interagem para trocar latência por vazão e reduzir o uso de rede e disco. Você pratica Apache Kafka & Stream Processing Fundamentals com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Apache Kafka & Stream Processing Fundamentals?

Nenhuma experiência prévia é necessária. Apache Kafka & Stream Processing Fundamentals no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Agrupamento, compressão e ajuste de linger.ms”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Apache Kafka & Stream Processing Fundamentals?

Sim. Cada aula de Apache Kafka & Stream Processing Fundamentals inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Desempenho de produtores e consumidores
  2. Configuração e ajuste de intermediários
  3. Otimização de E/S de disco e rede
  4. Agrupamento, compressão e ajuste de linger.ms
← Voltar para Apache Kafka & Stream Processing Fundamentals