Node.js › Performance Optimization & Profiling
What is load testing, and how would you use a tool like autocannon or k6 to benchmark a Node.js API's throughput and latency?
IntermediateAnswer
Load testing simulates many concurrent users or requests against an application to measure how its throughput (requests handled per second) and latency (response time, particularly at higher percentiles like p95/p99) behave under realistic or stress-level traffic, revealing bottlenecks and capacity limits before they're discovered in production -- tools like autocannon (lightweight, Node.js-native) or k6 (more full-featured, scriptable) send configurable concurrent request loads and report detailed statistics.
npx autocannon -c 100 -d 30 http://localhost:3000/api/users
# -c 100: 100 concurrent connections
# -d 30: run for 30 seconds
# Reports: requests/sec, latency percentiles (p50, p95, p99), throughput, errorsReal-world example A team preparing for an anticipated traffic spike during a product launch runs autocannon against a staging environment configured to match production capacity, discovering that response latency degrades sharply beyond roughly 200 concurrent connections, prompting them to add an additional server instance before the actual launch.