0Pricing
Apache Kafka & Stream Processing Fundamentals · レッスン

バッチ処理・圧縮・lingerの調整

プロデューサーのバッチ処理、linger.ms、圧縮がどのように連動してレイテンシとスループットを調整し、ネットワークとディスクの使用量を削減するかを学びます。

「バッチ処理・圧縮・lingerの調整」はCoddyKit上の無料Apache Kafka & Stream Processing Fundamentalsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはApache Kafka & Stream Processing Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

よくある質問

「バッチ処理・圧縮・lingerの調整」レッスンは無料ですか?

はい。「バッチ処理・圧縮・lingerの調整」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Apache Kafka & Stream Processing Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。

「バッチ処理・圧縮・lingerの調整」で何を学びますか?

プロデューサーのバッチ処理、linger.ms、圧縮がどのように連動してレイテンシとスループットを調整し、ネットワークとディスクの使用量を削減するかを学びます。 ブラウザで直接実行するハンズオンコードでApache Kafka & Stream Processing Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Apache Kafka & Stream Processing Fundamentalsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのApache Kafka & Stream Processing Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「バッチ処理・圧縮・lingerの調整」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このApache Kafka & Stream Processing Fundamentalsレッスンでコードを書いて実行できますか?

はい。すべてのApache Kafka & Stream Processing Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. プロデューサーとコンシューマーのパフォーマンス
  2. ブローカーの設定とチューニング
  3. ディスクI/Oとネットワークの最適化
  4. バッチ処理・圧縮・lingerの調整
← Apache Kafka & Stream Processing Fundamentalsに戻る