Performance monitoring
.NET performance monitoring
.NET apps slow down most often from thread pool starvation, allocation-heavy code and slow dependencies. dotnet-counters and traces show all three.
3 min read10 sectionsUpdated
On this page
| Counter | Meaning | Worry when |
|---|---|---|
| ThreadPool Queue Length | Work waiting for a thread | Grows under load |
| ThreadPool Thread Count | Threads in the pool | Keeps climbing slowly (injection to fight starvation) |
| GC Heap Size, Gen 2 GC count | Long-lived memory and expensive collections | Heap grows; frequent gen 2 |
| Allocation rate | Bytes allocated per second | High on hot endpoints |
| Requests per second, failed requests | Traffic and errors | Failures rise |
Typical .NET bottlenecks
- Sync over async (
.Result,.Wait()) blocks thread pool threads and causes starvation under load. - New HttpClient per request exhausts sockets; use IHttpClientFactory.
- EF Core N+1 with lazy loading; use
Includeor projections. See finding slow database queries. - Large object heap allocations (big arrays and strings) trigger expensive collections.
- Logging with string interpolation on hot paths allocating even when the level is off.
Tracing and metrics
Add AddOpenTelemetry() with ASP.NET Core, HttpClient and runtime instrumentation and an OTLP exporter; the full Program.cs is in OpenTelemetry for .NET. For CPU, dotnet-trace collect records a trace you can view as a flame graph; for memory, dotnet-gcdump captures the heap.
| Signal | Source | Why |
|---|---|---|
| Latency per endpoint | OpenTelemetry ASP.NET Core instrumentation | Find the slow endpoints |
| Thread pool queue length and starvation | dotnet-counters (System.Runtime) | Sync-over-async blocks threads and stalls everything |
| GC heap size and time in GC | dotnet-counters | Memory pressure and pauses |
| Exceptions per second | dotnet-counters | A spike often precedes errors users see |
| Database and HTTP client spans | EF Core / SqlClient / HttpClient instrumentation | Most latency is in dependencies |
# live runtime counters for a running process
dotnet-counters monitor --process-id 1234 System.Runtime
# a short trace when something is slow
dotnet-trace collect --process-id 1234 --duration 00:00:30Common .NET performance issues
- Sync-over-async (.Result or .Wait() on tasks) exhausts the thread pool under load; requests queue while CPU is low.
- HttpClient created per request exhausts sockets; use IHttpClientFactory.
- Large object heap growth from big buffers and strings; pool buffers.
See OpenTelemetry for .NET and IIS monitoring.
How do I confirm thread pool starvation?
Queue length grows while CPU is low and latency rises; a dump shows many threads blocked in .Result or .Wait. Remove the blocking calls.
Server or workstation GC?
ASP.NET Core uses server GC by default, which suits multi-core servers. In small containers, consider the GC heap limits and test both.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- OpenTelemetry for Flask: Instrument a Flask app with OpenTelemetry, in code or with zero code: trace routes, SQLAlchemy and outgoing calls, and export to VitalRix.
- Go performance monitoring: Monitor Go services: goroutine counts, GC and heap, request latency per handler, pprof profiling in production and OpenTelemetry tracing with otelhttp.
- PHP performance monitoring: Monitor PHP and Laravel apps: request latency, PHP-FPM worker saturation, OPcache hit rate, slow queries, external calls and errors.
- Python performance monitoring: Monitor Python web apps: request latency per route, worker saturation, the GIL and CPU-bound code, database time, Celery queues and memory.
- Ruby and Rails performance monitoring: Monitor Ruby on Rails apps: request latency per action, Puma thread and worker saturation, ActiveRecord queries, Sidekiq queues, memory bloat and GC.
- OpenTelemetry for Django: Trace a Django app with OpenTelemetry: auto-instrument views and the ORM, run under gunicorn safely, trace Celery tasks and export to VitalRix.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.