Phase 24 of 30 · Topic 24.3

Server GC vs Workstation GC & Background / Non-Concurrent GC

1Concept

Workstation GC runs on a single thread alongside the app. Server GC creates dedicated GC threads and separate heap segments per physical CPU core for high-throughput multi-core server scale.

2Architecture Diagram

Workstation GC (Desktop / Mobile):
[ Core 1 ] [ Core 2 ] ──> Shared Single Managed Heap (Low RAM footprint)

Server GC (Cloud APIs / Docker / Kubernetes):
[ Core 1 ] ──> Dedicated Server GC Thread 1 + Dedicated Heap Segment 1
[ Core 2 ] ──> Dedicated Server GC Thread 2 + Dedicated Heap Segment 2 (Max Throughput!)

3Code Example

C# 13 & .NET 9
using System;
using System.Runtime;

public class GcModeDemo
{
    public static void Main()
    {
        Console.WriteLine($"Is Server GC Active: {GCSettings.IsServerGC}");
        Console.WriteLine($"GC Latency Mode: {GCSettings.LatencyMode}");
    }
}

4Expected Output

Is Server GC Active: True
GC Latency Mode: Interactive

5Key Takeaways

  • ASP.NET Core uses Server GC by default.
  • Set `<ServerGarbageCollection>true</ServerGarbageCollection>` in project files for backend microservices.
  • Use `GCLatencyMode.SustainedLowLatency` in trading/real-time systems.