In .NET 10, how do workstation GC, server GC and DATAS differ, and which does a console or ASP.NET Core app get by default?
answer
- one heap or one per CPU
- background is a sub-mode
- the Web SDK flips one property
- DATAS rides on server GC
- default since .NET 9
basics
~20 sWorkstation GC uses one heap and collects on the allocating thread; server GC collects up to one heap per logical CPU on dedicated threads. Console apps default to workstation, ASP.NET Core apps to server, whose heap count DATAS has adapted since .NET 9.
solid answer
~50 s**Workstation GC** keeps one heap and runs the collection on the thread that triggered it, at normal priority, which keeps memory and CPU use small. **Server GC** collects in parallel on dedicated GC threads, classically one heap and one thread per logical CPU, trading memory and CPU for throughput; on a machine with one logical CPU the runtime uses workstation GC whatever you ask for. Both run **background GC** for gen 2 by default (`System.GC.Concurrent`). A plain `Microsoft.NET.Sdk` app gets workstation GC; `Microsoft.NET.Sdk.Web` sets `ServerGarbageCollection` to true. **DATAS** (dynamic adaptation to application sizes) has been on by default since .NET 9 and applies only to server GC: it starts with one heap, grows or shrinks the heap count and sizes the gen 0 budget from the long-lived data, so the heap tracks the workload instead of the core count. You turn it off with `GarbageCollectionAdaptationMode` set to 0.
code
xml · 11 lines<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Server GC: one heap and one GC thread per logical CPU, sized by DATAS. -->
<ServerGarbageCollection>true</ServerGarbageCollection>
<!-- Background gen 2 collections: already the default, written down for review. -->
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>
</Project>go deeper
Recall that workstation GC is the console default, server GC the ASP.NET Core default, and that server GC uses a heap per logical CPU.
Explain how the flavors differ in threads, heaps and resource use, what background GC covers, and what DATAS changes about server GC since .NET 9.
Show you can pick and verify a flavor per deployment: dense hosts, single-CPU containers and bursty services each need a different answer, checked at run time.
Frame the choice as a fleet trade between throughput and memory density, and decide who may override the default and with what evidence.
## Two flavors and a sub-mode The .NET runtime ships one garbage collector with two main **flavors**, workstation and server, and a sub-mode, **background** versus non-concurrent, that applies to either. Since .NET 8 a third behaviour, **DATAS**, can sit on top of server GC, and since .NET 9 it does so by default. ## Workstation GC - One managed heap for the whole process. - A collection runs on the user thread that triggered it, at that thread's normal priority, so it competes with the app's other threads for CPU. - It is the default for standalone apps, and the runtime always uses it on a machine with a single logical CPU, even when the configuration asks for server GC (a run with `DOTNET_PROCESSOR_COUNT=1` reported `GCSettings.IsServerGC` as `False` despite `ServerGarbageCollection` being true). - The docs suggest it, with concurrent GC disabled, when you run hundreds of instances of an app on one machine. ## Server GC - Without DATAS, one heap **and** one dedicated GC thread per logical CPU (DATAS varies the heap count, see below); all heaps are collected at the same time, and on Windows the GC threads run at `THREAD_PRIORITY_HIGHEST`. - Each heap has its own small object heap and large object heap; objects on different heaps can reference each other. - On the same heap size it collects faster than workstation GC, because several threads share the work. - It is resource-hungry: twelve server-GC processes on four logical CPUs that collect at the same moment schedule twelve GC threads per CPU. `System.GC.HeapCount` (`DOTNET_GCHeapCount`) limits the heap count. ## Background GC Background GC (`System.GC.Concurrent`, on by default) runs **gen 2** collections on dedicated threads while managed threads keep running, and lets gen 0 and gen 1 **foreground** collections happen in the meantime; those foreground collections suspend all managed threads. Workstation background GC uses one background thread; server background GC uses several, typically one per logical CPU. Gen 0 and gen 1 collections are never background, because they are short. ## DATAS Dynamic adaptation to application sizes changes how server GC sizes itself: 1. It sets the maximum allocation allowed before the next collection from the **long-lived data size**, not from throughput alone. 2. It starts with **one heap** and adds or removes heaps as needed, so it ranges between workstation-like (one heap) and server-like (one per core). 3. It aims at a target throughput cost: 2% by default (`System.GC.DTargetTCP`, .NET 9). 4. It runs full compacting collections when fragmentation gets too high. The .NET docs report working-set reductions above 80% on a 48-core benchmark for a 2-3% throughput loss, and many more gen 0 and gen 1 collections. Because it starts with one heap, allocating threads can wait at startup or when load ramps up, before the heap count catches up. ## Defaults and the three spellings | Setting | runtimeconfig.json | MSBuild property | Environment variable | Default | |---|---|---|---|---| | Server vs workstation | `System.GC.Server` | `ServerGarbageCollection` | `DOTNET_gcServer` | workstation (`false`); the Web SDK sets `true` | | Background GC | `System.GC.Concurrent` | `ConcurrentGarbageCollection` | `DOTNET_gcConcurrent` | `true` | | DATAS | `System.GC.DynamicAdaptationMode` | `GarbageCollectionAdaptationMode` | `DOTNET_GCDynamicAdaptationMode` | `1` since .NET 9 (server GC only) | The MSBuild properties are written into the app's runtimeconfig.json at build time; the environment variable is read when the process starts, and in a .NET 10 run `DOTNET_gcServer=0` overrode `System.GC.Server: true` from runtimeconfig.json. ## Choosing - A request-serving app on several dedicated cores: server GC with DATAS, the Web SDK default. - Small tools, sidecars and processes packed many to a machine: workstation GC, or server GC with a capped `GCHeapCount`. - A latency-sensitive desktop app: workstation GC with background GC on. - Turn DATAS off only when a load test shows a throughput loss you cannot accept. At run time, `GCSettings.IsServerGC` and `GC.GetConfigurationVariables()` show what the process actually got.
- Does background GC remove gen 2 pauses in .NET?No. Background GC marks gen 2 on dedicated threads while managed threads run and lets gen 0 and gen 1 foreground collections happen meanwhile, but those foreground collections suspend every managed thread, and the GC can still choose a blocking gen 2, for instance under high memory load. It shortens full-collection pauses; it does not remove them.
- Why can many server-GC processes on one machine do worse than workstation GC?Each server-GC process starts a GC thread per logical CPU, at high priority on Windows. Twelve such processes on four CPUs can put twelve GC threads on each CPU when their collections coincide, so they fight for CPU and their pauses stretch. Capping `System.GC.HeapCount`, letting DATAS shrink the heap count, or using workstation GC for densely packed processes avoids it.
- How do you confirm which GC flavor a running .NET process has?`GCSettings.IsServerGC` and `GCSettings.LatencyMode` report the flavor and mode, and `GC.GetConfigurationVariables()` returns the effective settings, such as `ServerGC`, `ConcurrentGC`, `HeapCount` and `GCDynamicAdaptationMode`. Read them with care: `GCDynamicAdaptationMode` shows 1 under workstation GC too, although DATAS has no effect there.
- Server GC is always faster, so every app should turn it on.
- DATAS can be switched on for a workstation-GC console app to shrink its heap.
- Background GC makes gen 0 and gen 1 collections run concurrently too.
- A console app on a multi-core machine gets server GC automatically.
- Asking for server GC on a single-CPU machine still gets you server GC.
Assumes .NET 10; DATAS was opt-in in .NET 8 and has been on by default for server GC since .NET 9.