Tutorials ASP.NET Core Complete Tutorial (ShopNest)
Performance Testing and Load Testing ASP.NET Core APIs
Learn Performance Testing and Load Testing ASP.NET Core APIs in our free ASP.NET Core Complete Tutorial (ShopNest) series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.
On this page
Introduction
Before ShopNest flash sales, know your API limits — k6 load tests and BenchmarkDotNet micro-benchmarks reveal DB and CPU bottlenecks before customers do.
After this article you will
- Run k6 load scripts against ShopNest API
- Use BenchmarkDotNet for hot path code
- Profile with dotnet-counters and dotnet-trace
- Interpret latency percentiles (p95, p99)
- Optimize based on profiling evidence
Prerequisites
- Article 56 — Testing EF Core
- ShopNest Order Service / API from prior modules
Concept deep-dive
// k6 script — shopnest-load.js
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '1m', target: 50 },
{ duration: '3m', target: 200 },
{ duration: '1m', target: 0 },
],
thresholds: { http_req_duration: ['p(95)<500'] },
};
export default function () {
const res = http.get('https://api.shopnest.local/api/v1/products?page=1');
check(res, { 'status 200': (r) => r.status === 200 });
sleep(1);
}
// BenchmarkDotNet
[MemoryDiagnoser]
public class OrderTotalBenchmark
{
[Benchmark]
public decimal CalculateTotal() => OrderCalculator.Compute(_sampleLines);
}
Metrics: ASP.NET Core exposes requests/sec, active connections. Watch SQL CPU and connection pool exhaustion under load.
Hands-on — ShopNest Production API Optimization
- k6 run against local ShopNest product list API.
- Baseline p95 latency; add Redis cache; re-run and compare.
- dotnet-counters monitor System.Runtime and Microsoft.AspNetCore.Hosting.
- Document bottleneck (missing index vs no cache) and fix.
Common errors & best practices
- Load testing production without approval — use staging.
- Optimizing without measuring — guesswork wastes time.
- Ignoring connection pool limits under high concurrency.
Interview questions
Q: p95 latency?
A: 95% of requests faster than this value — SLA metric.
Q: k6 vs JMeter?
A: k6 scriptable in JS, developer-friendly; JMeter GUI-heavy.
Q: BenchmarkDotNet purpose?
A: Micro-benchmark C# methods with statistical rigor.
Summary
- Load test before major ShopNest launches
- k6 stages simulate ramp-up traffic realistically
- Profile first — cache and indexes fix most API slowness
- p95/p99 matter more than average latency
Previous: Testing EF Core
Next: Test-Driven Development
FAQ
Artillery alternative?
YAML-based load tests — similar to k6 for HTTP.
Load test auth endpoints?
Use k6 setup() to fetch JWT once, reuse in VUs.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!