Skip to content

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

Live counters

bash
dotnet tool install --global dotnet-counters
dotnet-counters monitor --process-id <pid> System.Runtime Microsoft.AspNetCore.Hosting

What to watch

CounterMeaningWorry when
ThreadPool Queue LengthWork waiting for a threadGrows under load
ThreadPool Thread CountThreads in the poolKeeps climbing slowly (injection to fight starvation)
GC Heap Size, Gen 2 GC countLong-lived memory and expensive collectionsHeap grows; frequent gen 2
Allocation rateBytes allocated per secondHigh on hot endpoints
Requests per second, failed requestsTraffic and errorsFailures 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 Include or 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.

What to watch in .NET applications

SignalSourceWhy
Latency per endpointOpenTelemetry ASP.NET Core instrumentationFind the slow endpoints
Thread pool queue length and starvationdotnet-counters (System.Runtime)Sync-over-async blocks threads and stalls everything
GC heap size and time in GCdotnet-countersMemory pressure and pauses
Exceptions per seconddotnet-countersA spike often precedes errors users see
Database and HTTP client spansEF Core / SqlClient / HttpClient instrumentationMost latency is in dependencies
bash
# 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:30

Common .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.

Frequently asked questions

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

  • 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.