Pengelompokan, Kompresi, dan Penyetelan Linger
Pelajari cara pengelompokan produsen, linger.ms, dan kompresi saling berinteraksi untuk menukar latensi dengan throughput serta mengurangi penggunaan jaringan dan disk.
Pengelompokan, Kompresi, dan Penyetelan Linger adalah pelajaran Apache Kafka & Stream Processing Fundamentals gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Apache Kafka & Stream Processing Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Apache Kafka & Stream Processing Fundamentals mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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.mselapses, 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.msand 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.mscontrol batch size and the latency trade-off.- Compression (lz4/zstd) saves network, disk, and replication bandwidth.
buffer.memorybounds in-flight data.- Verify with batch-size-avg and compression-rate-avg metrics.
Belajar Apache Kafka & Stream Processing Fundamentals dengan tutor AI — gratis
Tulis dan jalankan kode asli di browser kamu, dapatkan bantuan instan dari tutor AI 24/7, dan lanjutkan di mana kamu tinggalkan di web atau aplikasi.
- Kursus
- 12
- Pelajaran
- 48
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Pengelompokan, Kompresi, dan Penyetelan Linger” gratis?
Ya — teks lengkap “Pengelompokan, Kompresi, dan Penyetelan Linger” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Apache Kafka & Stream Processing Fundamentals, upgrade ke CoddyKit PRO. Kursus Apache Kafka & Stream Processing Fundamentals mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Pengelompokan, Kompresi, dan Penyetelan Linger”?
Pelajari cara pengelompokan produsen, linger.ms, dan kompresi saling berinteraksi untuk menukar latensi dengan throughput serta mengurangi penggunaan jaringan dan disk. Kamu berlatih Apache Kafka & Stream Processing Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Apache Kafka & Stream Processing Fundamentals?
Tidak diperlukan pengalaman sebelumnya. Apache Kafka & Stream Processing Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Pengelompokan, Kompresi, dan Penyetelan Linger” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Apache Kafka & Stream Processing Fundamentals ini?
Ya. Setiap pelajaran Apache Kafka & Stream Processing Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Performa Producer & Consumer
- Konfigurasi & Penyetelan Broker
- Optimalisasi I/O Disk & Jaringan
- Pengelompokan, Kompresi, dan Penyetelan Linger