<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Umesh Sehgal on Medium]]></title>
        <description><![CDATA[Stories by Umesh Sehgal on Medium]]></description>
        <link>https://medium.com/@SehgalUmesh?source=rss-d5ca84850e70------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zZVdADtm70XSUk35__AJXw.png</url>
            <title>Stories by Umesh Sehgal on Medium</title>
            <link>https://medium.com/@SehgalUmesh?source=rss-d5ca84850e70------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:26:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@SehgalUmesh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tackling Disk Write Latency: Journaling and Best Practices in Kafka]]></title>
            <link>https://medium.com/@SehgalUmesh/tackling-disk-write-latency-journaling-and-best-practices-in-kafka-832c83b3bd12?source=rss-d5ca84850e70------2</link>
            <guid isPermaLink="false">https://medium.com/p/832c83b3bd12</guid>
            <dc:creator><![CDATA[Umesh Sehgal]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 07:45:03 GMT</pubDate>
            <atom:updated>2025-01-05T08:13:06.201Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tackling Disk Write Latency: Journaling and Best Practices in Kafka</h3><p>Latency in Kafka is often a topic of keen interest, especially when it comes to mission-critical applications. While network bandwidth and producer/consumer configurations usually steal the spotlight, disk write latency driven by journal settings on file systems is an equally pivotal — and often overlooked — factor. Let’s dive into how journaling impacts Kafka’s performance and explore best practices around its configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*TAOG0yfwEtgUQiS9W7TyLA.png" /></figure><h3>What is a Journal, and Why Does It Matter?</h3><p>A journal is a mechanism used by file systems to maintain consistency. It records changes to metadata (and sometimes data) in a separate log before applying them to the actual file system. This ensures that even in case of a system crash, the file system can recover to a consistent state. While this process guarantees robustness, it can introduce latency. Different journaling modes balance trade-offs between consistency, performance, and latency:</p><h3>Visualizing Journaling Modes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*2OLDAI8ibg3zzqnZLrGzmQ.png" /></figure><p><strong>Ordered Mode (Default)</strong>: Data is written to disk first, followed by metadata. This ensures consistency but introduces delays for applications like Kafka that require high-speed sequential writes.</p><p><strong>Writeback Mode</strong>: Metadata is written to the journal without enforcing a strict order for data. This improves performance but might lead to inconsistent states if a crash occurs.</p><p><strong>Data Mode</strong>: Both data and metadata are journaled, offering maximum consistency but at the cost of performance.</p><h3>The Impact of Journal Modes on Kafka</h3><p>Kafka’s architecture revolves around appending messages to logs stored on disk. When the journal mode is set to “ordered,” Kafka’s sequential writes can experience added latency due to synchronization delays. Given how journaling locking mechanism works, a single slow write could cause lock contention and a cascade of slow requests.</p><p>ext4 offers three journaling modes: data, ordered and writeback. The default mode is ordered and compared to the most performant mode, writeback, it guarantees that the data is written to the main file system prior to the metadata being committed to the journal. In context of Kafka (<a href="https://kafka.apache.org/documentation/#ext4">docs</a>), since it does not rely on journaling behavior for data recovery, switching the mode to writeback should help reduce write latency.</p><h3>Monitoring Journal Performance</h3><p>Visibility into journal-induced latency is crucial for diagnosing bottlenecks. Key tools include:</p><p><strong>Kafka Metrics</strong>: Track broker-level metrics such as LogFlushRateAndTimeMs for insights into disk performance.</p><p><strong>iostat/dstat</strong>: Monitor disk write latency and throughput.</p><p><strong>iotop</strong>: Identify Kafka’s I/O patterns and their impact on the journal.</p><h3>Advanced Monitoring with eBPF Tools</h3><p>Modern tools leveraging eBPF (extended Berkeley Packet Filter) offer fine-grained insights into file system operations and write latencies. These tools run in the Linux kernel, offering minimal overhead while capturing detailed telemetry. Some notable eBPF tools include:</p><p><strong>bpftrace</strong>: Create custom scripts to trace file system activities and journal write events. For example, you can trace ext4_sync_file to measure latency for sync operations:</p><pre>bpftrace -e &#39;tracepoint:ext4:ext4_sync_file { printf(&quot;Sync latency: %d\n&quot;, args-&gt;latency); }&#39;</pre><p><strong>bcc (BPF Compiler Collection)</strong>: Includes pre-built tools like ext4slower to detect slow ext4 operations and xfsslower for XFS.</p><pre>sudo ./ext4slower 10  # Logs ext4 operations taking longer than 10ms.</pre><pre>sudo ./xfsslower 10   # Logs XFS operations taking longer than 10ms.</pre><p><a href="https://github.com/iovisor/bcc"><strong>iovisor/bcc</strong></a>: Offers a rich set of pre-built eBPF programs to monitor disk I/O, journal writes, and bottlenecks in real-time.</p><p>These tools provide unprecedented visibility into how file system operations, including journal writes, impact Kafka’s performance.</p><h3>Best Practices for Journal Settings on ext4 and XFS</h3><h4>ext4</h4><p>ext4 is a widely used default file system, and its journaling options can be optimized for Kafka:</p><p><strong>Enable Writeback Mode</strong>: Use mount -o data=writeback to configure the journal mode. This significantly improves write throughput for Kafka workloads.</p><p><strong>Fast Commit</strong>: Latest versions of Linux supports fast commits. It makes the journaling method more light weight improving the write latencies.</p><p><strong>Tune Commit Interval</strong>: Adjust the commit interval (commit=nrsec) to balance durability and performance. Increasing this value can reduce the frequency of journal writes. For some of the scenarios, the reverse may also be beneficial. This should be adjusted based on the use case and scenarios.</p><p><strong>Use Delayed Allocation</strong>: ext4’s allocate-on-flush feature reduces fragmentation and enhances performance for sequential writes.</p><h4>XFS</h4><p>As per Kafka official documentation XFS filesystem have shown it to have better performance characteristics for Kafka’s workload with no compromise in stability.</p><p>The XFS performance also show less variability in disk performance and result in much better local times (160ms vs. 250ms+ for the best EXT4 configuration refer: <a href="https://kafka.apache.org/documentation/#filesystems">Kafka docs</a>)</p><p>The XFS filesystem is auto tuned for the most case, so in general does not require any change in the default settings, either at filesystem creation time or at mount. However, some parameter which can be worth consideration for certain use cases are:</p><p><strong>Disable Atime Updates</strong>: Mount XFS with the noatime option to avoid unnecessary metadata updates during reads. Kafka does not rely on the atime attributes at all, so it is safe to disable this.</p><p><strong>Optimize Metadata Buffers</strong>: XFS manages metadata more efficiently but ensure adequate buffer sizes to manage high write loads.</p><p><strong>Journal Tuning</strong>: While XFS does not expose direct journal mode toggling like ext4, its multithreaded I/O capabilities inherently reduce journaling overhead.</p><p><strong>Enable Large I/O Operations</strong>: Use the largeio mount option to align I/O requests with the stripe size of the storage device, enhancing throughput for Kafka workloads.</p><h3>Wrapping Up</h3><p>Optimizing journal settings is a critical step for reducing Kafka’s disk write latencies. Switching to “writeback” mode on ext4, leveraging XFS’s advanced features, and tuning system parameters can deliver substantial performance gains for mission-critical applications. Combining these optimizations with eBPF-based monitoring ensures that you can detect, diagnose, and resolve latency issues effectively. By understanding and managing journal behavior, you can ensure Kafka’s durability without compromising on latency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=832c83b3bd12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>