Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/docs/execution/parallelism.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ TUNIT_ADAPTIVE_PARALLELISM=1 dotnet run --project MyTests

You can also set `context.Settings.Parallelism.Adaptive = true` in a `[Before(HookType.TestDiscovery)]` hook.

The run starts at the limit a run without adaptive parallelism uses: `--maximum-parallel-tests` when you set it, or 2 x the processor count. A move away from that limit has to pay for itself in completed tests per second. TUnit measures throughput, changes the limit, measures again, and puts the limit back if the change did not help. After a change that did not help, it waits before trying another: 15 seconds at first, doubling up to 2 minutes.
The run starts at the limit a run without adaptive parallelism uses: `--maximum-parallel-tests` when you set it, or 2 x the processor count. A move away from that limit has to pay for itself in completed tests per second. TUnit measures throughput, changes the limit, measures again, and puts the limit back if the change did not help. It starts only once two measurements in a row agree, so a suite whose throughput is still changing (a shared fixture starting, for example) is left alone until it settles. After a change that did not help, it waits before trying another. For a raise the wait is 5 seconds at first, doubling up to 30 seconds. For a lowering it is 15 seconds at first, doubling up to 2 minutes.

- **Raising.** When every slot is in use, CPU use is below 80%, memory use is below about 80%, and nothing is waiting for a CPU, TUnit raises the limit by half. It keeps the raise only if throughput rose by a fair share of it: 15% more for a 50% raise.
- **Lowering for CPU.** When the CPUs are saturated and work is waiting for one, TUnit lowers the limit by a quarter. It keeps the lower limit only if throughput held: one or more steps down may cost at most 7.5% in total. CPU-bound tests lose nothing with fewer running at once, so the lower limit stays. Tests that mostly wait on I/O do lose, so the limit goes back. TUnit never lowers the limit below the processor count for this reason.
- **Raising.** When every slot is in use, CPU use is below 80%, memory use is below about 80%, and nothing is waiting for a CPU, TUnit raises the limit by half. It keeps the raise only if throughput rose by a fair share of it: 15% more for a 50% raise. A raise above the starting limit that leaves the CPUs 90% busy or more is put back within about half a second, without waiting for the measurement.
- **Lowering for CPU.** When the CPUs are saturated and work is waiting for one, TUnit lowers the limit by a quarter. It keeps the lower limit only if throughput held: one or more steps down may cost at most 7.5% in total. CPU-bound tests lose nothing with fewer running at once, so the lower limit stays. Tests that mostly wait on I/O do lose, so the limit goes back. Above the starting limit, saturated CPUs are enough to try a lower limit, whether or not work is waiting. TUnit never lowers the limit below the processor count for this reason.
- **Lowering for memory.** When the machine or container is nearly out of memory, TUnit halves the limit at once, without a trial, because swapping or an out-of-memory kill costs more than a slower run.
- **Returning.** Below the starting limit, TUnit steps back up as soon as the machine has headroom, and otherwise tries the step up like any other raise.

Expand Down
5 changes: 3 additions & 2 deletions src/TUnit.Engine/Scheduling/AdaptiveParallelismController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void Sample(ParallelismLimits limits)
&& TrySetLimit(decision.Limit, out var previousLimit, out var limit)
&& _logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug($"Adaptive parallelism: limit {previousLimit} -> {limit} ({Describe(decision.Change)}); CPU {cpuUtilization * 100:0}%, memory load {memoryLoad * 100:0}%");
_logger.LogDebug($"Adaptive parallelism: limit {previousLimit} -> {limit} ({Describe(decision.Change)}); CPU {cpuUtilization * 100:0}% in the latest sample, memory load {memoryLoad * 100:0}%");
}

previousCpuTime = cpuTime;
Expand Down Expand Up @@ -239,9 +239,10 @@ private bool TrySetLimit(int requestedLimit, out int previousLimit, out int limi
{
AdaptiveLimitChange.Probe => "probing for more throughput",
AdaptiveLimitChange.ProbeReverted => "the last raise did not improve throughput",
AdaptiveLimitChange.ProbeAborted => "the last raise left the CPUs busy",
AdaptiveLimitChange.Recovery => "pressure eased",
AdaptiveLimitChange.MemoryPressure => "memory pressure",
AdaptiveLimitChange.CpuSaturation => "CPUs saturated and work is queuing for a thread; checking that fewer tests cost no throughput",
AdaptiveLimitChange.CpuSaturation => "CPUs saturated; checking that fewer tests cost no throughput",
AdaptiveLimitChange.LowerReverted => "the lower limit cost throughput",
_ => change.ToString(),
};
Expand Down
Loading
Loading