التحزيم والضغط وضبط Linger
تعلّم كيف يتفاعل تحزيم المنتج وlinger.ms والضغط للموازنة بين زمن الاستجابة ومعدل المعالجة وتقليل استخدام الشبكة والقرص.
التحزيم والضغط وضبط Linger درس مجاني في Apache Kafka & Stream Processing Fundamentals على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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.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.
الأسئلة الشائعة
هل درس «التحزيم والضغط وضبط Linger» مجاني؟
نعم — نص درس «التحزيم والضغط وضبط Linger» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Apache Kafka & Stream Processing Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.
ماذا ستتعلم في «التحزيم والضغط وضبط Linger»؟
تعلّم كيف يتفاعل تحزيم المنتج وlinger.ms والضغط للموازنة بين زمن الاستجابة ومعدل المعالجة وتقليل استخدام الشبكة والقرص. تتمرن على Apache Kafka & Stream Processing Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Apache Kafka & Stream Processing Fundamentals؟
لا تُشترط خبرة سابقة. Apache Kafka & Stream Processing Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «التحزيم والضغط وضبط Linger»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Apache Kafka & Stream Processing Fundamentals هذا؟
نعم. كل درس في Apache Kafka & Stream Processing Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- أداء المنتجين والمستهلكين
- إعداد الوسيط وضبطه
- تحسين إدخال وإخراج القرص والشبكة
- التحزيم والضغط وضبط Linger