ASP.NET Core Interview Question #199

How should ASP.NET Core performance be measured and diagnosed?

Performance, Caching & HTTP Senior Advanced

Quick Interview Answer

Measure before optimizing. Use production metrics, distributed traces, structured logs, profilers, database query analysis, and controlled load testing to determine where time and resources are actually being consumed.

Detailed Explanation

Measure before optimizing. Use production metrics, distributed traces, structured logs, profilers, database query analysis, and controlled load testing to determine where time and resources are actually being consumed.

Useful measurements include request latency percentiles, throughput, error rate, CPU, memory, GC behavior, thread-pool pressure, database duration, downstream-call duration, and cache effectiveness.

Test realistic workloads and compare changes against a baseline. A micro-optimization that does not affect the real bottleneck may add complexity without improving user experience.

Code Example

var stopwatch = Stopwatch.StartNew();

await next(context);

stopwatch.Stop();

_logger.LogInformation(
    "Request {Path} completed in {ElapsedMs} ms",
    context.Request.Path,
    stopwatch.ElapsedMilliseconds);