Advertisement
Advanced ASP.NET Core, Hosting Models: Kestrel, IIS & Reverse Proxies

How would you configure Kestrel's connection limits and thread pool behavior to handle high-concurrency production traffic without exhausting server resources?

Short answer

Kestrel's Limits.MaxConcurrentConnections and MaxConcurrentUpgradedConnections cap the total simultaneous connections to prevent unbounded resource consumption under extreme load, while the .NET thread pool's own minimum thread count (ThreadPool.SetMinThreads) can be tuned to…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Kestrel's Limits.MaxConcurrentConnections and MaxConcurrentUpgradedConnections cap the total simultaneous connections to prevent unbounded resource consumption under extreme load, while the .NET thread pool's own minimum thread count (ThreadPool.SetMinThreads) can be tuned to avoid a slow thread-pool-growth ramp-up causing artificial latency spikes at the very start of a traffic surge -- these settings should be tuned based on load testing against your specific application's actual resource consumption per connection/request, not applied as generic defaults.
builder.WebHost.ConfigureKestrel(options => {
    options.Limits.MaxConcurrentConnections = 1000;
    options.Limits.MaxConcurrentUpgradedConnections = 1000;  // e.g., WebSocket connections
});

// In Program.cs, before the host builds
ThreadPool.SetMinThreads(workerThreads: 200, completionPortThreads: 200);
Real-world example
An API experiencing latency spikes at the very start of sudden traffic surges (correlated with slow thread pool growth) sets a higher ThreadPool minimum thread count after load testing confirmed the default gradual ramp-up was the specific cause of those initial-spike latencies.
Likely follow-ups
  • What are the risks of setting MaxConcurrentConnections too low versus too high?
  • How do you determine the right MinThreads value through load testing rather than guessing?
Related topics