G1 Parallel Threads: Default Count & STW Impact
The `-XX:ParallelGCThreads` flag controls the number of threads used for Stop-The-World (STW) phases like Young GC and Remark; its default is often 5/8 of logical processors for systems with over 8 cores, or the number of logical processors if 8 or fewer.
The top 3
- G1's Default Parallel Thread Calculation Logic: The default `ParallelGCThreads` count for G1 GC is ergonomically determined: it matches the number of CPU cores for systems with 8 or fewer cores, and for systems with more than 8 cores, it uses `8 + (cores - 8) * 5/8`. This heuristic balances GC parallelism with potential system overhead.
- How Parallel Threads Reduce G1 STW Pause Durations: Increasing the number of `ParallelGCThreads` directly shortens "stop-the-world" (STW) pause times, especially during young generation collections, by allowing more worker threads to process garbage concurrently. However, setting it too high can introduce coordination overhead, diminishing returns.
- Tuning G1 Parallel Threads for ML Throughput vs. Latency: For throughput-intensive ML batch processing, `ParallelGCThreads` can be set closer to the number of available CPU cores to maximize GC work. For latency-sensitive interactive ML, a balanced approach is needed to meet pause time goals without excessive CPU contention, often implying a slightly lower count.
Sources
Open the full topic