<?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 Rajduvva on Medium]]></title>
        <description><![CDATA[Stories by Rajduvva on Medium]]></description>
        <link>https://medium.com/@rajduvva?source=rss-69cd514b1513------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ew_V8WwEomUUXI7-</url>
            <title>Stories by Rajduvva on Medium</title>
            <link>https://medium.com/@rajduvva?source=rss-69cd514b1513------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:28:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajduvva/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[G1GC Deep Dive: Tuning and Performance Optimization]]></title>
            <link>https://medium.com/@rajduvva/g1gc-deep-dive-tuning-and-performance-optimization-30acb5b5038e?source=rss-69cd514b1513------2</link>
            <guid isPermaLink="false">https://medium.com/p/30acb5b5038e</guid>
            <dc:creator><![CDATA[Rajduvva]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 09:25:31 GMT</pubDate>
            <atom:updated>2025-03-06T09:25:31.957Z</atom:updated>
            <content:encoded><![CDATA[<p>The Garbage First (G1) Garbage Collector (GC) is the default garbage collector in modern Java applications. Designed to balance throughput, latency, and pause time, G1GC is particularly beneficial for high-load, memory-intensive applications. However, tuning G1GC effectively requires in-depth monitoring and understanding of application behavior under different conditions. In this blog, we’ll explore G1GC tuning strategies and present a real-world case study of optimizing G1GC for a high-throughput financial transaction processing system.</p><h3>Understanding G1GC Mechanism</h3><p>G1GC divides the heap into regions and dynamically prioritizes garbage collection based on the application’s needs. It aims to collect garbage in a manner that minimizes pause times while maintaining throughput.</p><h3>Key Concepts:</h3><ol><li>Young Generation (Eden + Survivor regions) — Short-lived objects are allocated and quickly collected.</li><li>Old Generation — Long-lived objects promoted from the Young Generation.</li><li>Humongous Objects — Large objects allocated directly in the heap.</li><li>Mixed GC Cycles — A mix of Young and Old generation collection to optimize space reclamation.</li></ol><h3>Monitoring G1GC Performance</h3><p>To tune G1GC effectively, you need real-time data on how it behaves in your environment. Some key monitoring tools include:</p><ol><li>JVM Garbage Collection Logs (`-Xlog:gc*,gc+heap=debug`)</li><li>JVisualVM / JMC (Java Mission Control)</li><li>YourKit Profiler (for deep heap analysis)</li><li>Prometheus + Grafana (for long-term GC trend analysis)</li></ol><h3>Important Metrics to Observe</h3><ol><li>GC Pause Time (`Pause Young`, `Pause Full`)</li><li>Heap Usage (`Eden`, `Survivor`, `Old`)</li><li>Allocation Rate</li><li>Promotion Rate</li><li>GC Throughput (Time spent in GC vs. Time spent executing)</li></ol><h3>Common G1GC Performance Issues</h3><h3>High GC Pause Time</h3><p>Cause: Excessive Old Gen collections or large humongous object allocations.</p><p>Solution: Adjust heap region sizes (`-XX:G1HeapRegionSize`) and target pause time (`-XX:MaxGCPauseMillis`).</p><h3>Frequent Full GC Events</h3><p>Cause: Poor heap region management or fragmentation.</p><p>Solution: Increase heap size (`-Xms` and `-Xmx`), and optimize mixed GC (`-XX:G1MixedGCCountTarget`).</p><h3>High Promotion Rate to Old Gen</h3><p>Cause: Short-lived objects surviving too long.</p><p>Solution: Tune survivor space ratio (`-XX:SurvivorRatio`), and adjust young gen sizing (`-XX:G1NewSizePercent`).</p><h3>Case Study: Optimizing G1GC for a Financial Transaction Processing System</h3><h3>Scenario</h3><p>A large-scale financial transaction processing system was experiencing high GC pauses, frequent full GC cycles, and unpredictable latency spikes. The system handled millions of transactions per hour, requiring low-latency, high-throughput processing to ensure smooth financial operations.</p><h3>Initial Observations</h3><ol><li>Frequent Old Gen collections (~every 20s)</li><li>High GC pause times (up to 8 seconds)</li><li>High promotion rate to Old Gen (~70% of Young Gen objects promoted)</li><li>Humongous object allocations leading to unnecessary Full GC</li></ol><h3>Optimization Strategies</h3><h3>Reducing GC Pause Times</h3><p>Before: -XX:MaxGCPauseMillis=200 (Default)</p><p>After: -XX:MaxGCPauseMillis=50</p><h3>Tuning Heap Regions</h3><p>Before: Default region size (~2MB per region)</p><p>After: -XX:G1HeapRegionSize=8M</p><h3>Managing Young Generation Size</h3><p>Before: Default young gen sizing</p><p>After: -XX:G1NewSizePercent=35 -XX:G1MaxNewSizePercent=50</p><h3>Humongous Object Handling</h3><p>Before: High humongous object allocation leading to frequent Full GCs</p><p>After: Object pooling strategy and reducing large object creation</p><h3>Improving Throughput</h3><p>Before: -XX:G1MixedGCLiveThresholdPercent=85 (Default)</p><p>After: -XX:G1MixedGCLiveThresholdPercent=65</p><h3>Results After Optimization</h3><ol><li>GC pause times reduced from 8s to ~150ms</li><li>Throughput improved by 25%</li><li>Reduced Full GC occurrences from 5/hour to 1/day</li><li>Improved overall application responsiveness</li></ol><h3>Final Thoughts: G1GC Best Practices</h3><ol><li>Define Pause Time Goals — Use `-XX:MaxGCPauseMillis` to align GC behavior with performance requirements.</li><li>Monitor GC Logs Continuously — Identify problematic patterns and adapt accordingly.</li><li>Optimize Young Generation Size — Reduce Old Gen promotions for better performance.</li><li>Control Humongous Object Allocations — Use memory-efficient structures to avoid unnecessary Full GCs.</li><li>Adjust Mixed GC Tuning — Use `-XX:G1MixedGCLiveThresholdPercent` to ensure proactive old gen collection.</li></ol><p>By continuously analyzing GC logs and application behavior, you can fine-tune G1GC to provide a low-latency, high-performance experience in demanding environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30acb5b5038e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Virtual Threads: A Comprehensive Guide]]></title>
            <link>https://medium.com/@rajduvva/java-17-virtual-threads-a-comprehensive-guide-80db1b2750bb?source=rss-69cd514b1513------2</link>
            <guid isPermaLink="false">https://medium.com/p/80db1b2750bb</guid>
            <dc:creator><![CDATA[Rajduvva]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 08:50:08 GMT</pubDate>
            <atom:updated>2025-03-27T10:09:24.566Z</atom:updated>
            <content:encoded><![CDATA[<p>Java introduced Virtual Threads, a groundbreaking feature aimed at enhancing Java’s concurrency model. Virtual Threads provide lightweight, efficient, and scalable thread management, making them ideal for high-concurrency applications.</p><h3>1. What are Virtual Threads?</h3><p>Virtual Threads are lightweight user-mode threads that allow developers to create thousands or even millions of threads efficiently. Unlike traditional platform threads (OS-managed threads), virtual threads are managed by the JVM and are designed to reduce thread contention and improve resource utilization.</p><h3>Key Characteristics:</h3><ol><li>Lightweight and managed by the JVM</li><li>Each virtual thread is mapped to an underlying platform thread only when active</li><li>No direct binding to OS threads</li><li>Optimized for I/O-bound applications</li></ol><h3>2. How to Use Virtual Threads in Java</h3><h3>Creating Virtual Threads</h3><pre>public class VirtualThreadExample {<br> public static void main(String[] args) {<br> Runnable task = () -&gt; System.out.println(&quot;Executing on: &quot; + Thread.currentThread());<br> <br> // Creating a single virtual thread<br> Thread vThread = Thread.ofVirtual().start(task);<br> }<br> }</pre><h3>Using Executors for Virtual Threads</h3><pre>import java.util.concurrent.*;<br> <br> public class VirtualThreadExecutor {<br> public static void main(String[] args) {<br> try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {<br> for (int i = 0; i &lt; 10; i++) {<br> executor.submit(() -&gt; {<br> System.out.println(&quot;Running task on: &quot; + Thread.currentThread());<br> });<br> }<br> }<br> }<br> }</pre><h3>3. Pros and Cons of Virtual Threads</h3><h3>✅ Pros</h3><p>1. Massive Concurrency: Unlike platform threads, virtual threads can scale to millions, making them perfect for highly concurrent applications.<br> 2. Reduced Blocking Costs: Since they are managed by the JVM, blocking operations do not consume OS resources.<br> 3. Simplified Code: Eliminates the need for complex thread pooling and reactive programming frameworks.<br> 4. Better Resource Utilization: Reduces memory footprint and CPU overhead compared to traditional thread pools.</p><h3>❌ Cons</h3><p>1. Not Suitable for CPU-Bound Tasks: Virtual threads are optimized for I/O-bound tasks and offer limited benefits for CPU-intensive workloads.<br> 2. Instrumentation Limitations: Some existing profiling and debugging tools may not fully support virtual threads yet.<br> 3. Potential Starvation Risks: If too many virtual threads are blocked, it may impact responsiveness.</p><h3>4. Performance and Load Testing Results</h3><p>To evaluate the performance of virtual threads, we conducted a load test comparing virtual threads and platform threads.</p><h3>Test Setup:</h3><ol><li>Task: Simulating 100,000 concurrent HTTP requests.</li><li>Platform: Java running on an 32-core machine with 64GB RAM.</li></ol><h3>Results:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fOVTJhU1Rdf4VXMbs2j4gg.png" /></figure><h3>5. When to Use Virtual Threads?</h3><h3>Use Virtual Threads when:</h3><ol><li>You have highly concurrent I/O-bound workloads (e.g., web servers, database queries, messaging systems).</li><li>You need to simplify threading without worrying about thread pool management.</li></ol><h3>Avoid Virtual Threads when:</h3><ol><li>Your application is CPU-bound and requires heavy computation (e.g., video processing, machine learning).</li><li>You rely on existing instrumentation tools that do not yet support virtual threads well.</li></ol><h3>Conclusion</h3><p>Java’s Virtual Threads bring a significant improvement in concurrency management, especially for I/O-intensive applications. They enable massive scalability while reducing complexity and resource consumption. However, they are not a one-size-fits-all solution and should be used based on the specific needs of your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80db1b2750bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>