Performance Testing — Load, Stress, Chaos

লেসন ৪৩ / ৫০

Performance Test Types

Typeউদ্দেশ্য
LoadNormal + peak traffic সামলে?
Stressকখন ভাঙে? Breaking point
Spikeহঠাৎ 10x traffic
Soak/EnduranceLong duration (memory leak)
VolumeBig data set
ScalabilityResource বাড়ালে linear?

Key Metrics

  • Throughput (RPS)
  • Latency (p50, p95, p99)
  • Error rate (%)
  • Concurrent users
  • Resource utilization (CPU, mem)

k6 (modern) ⭐

import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '2m', target: 100 },   // ramp up
    { duration: '5m', target: 100 },   // stay
    { duration: '2m', target: 200 },   // spike
    { duration: '2m', target: 0 },     // ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  }
};

export default function () {
  const res = http.get('https://api.com/users');
  check(res, { 'status 200': (r) => r.status === 200 });
  sleep(1);
}

// Run: k6 run script.js

JMeter

Apache, GUI + CLI, mature। HTTP, DB, JMS testing।

Other Tools

Gatling (Scala DSL), Locust (Python), Artillery (Node), wrk/wrk2, ab (quick), Vegeta।

Profiling ⭐

Application-এ কোথায় slow — CPU/memory bottleneck find।

  • .NET — dotnet-trace, PerfView, JetBrains dotTrace
  • Node — --inspect, clinic.js, 0x flamegraph
  • Java — JProfiler, YourKit, async-profiler
  • Python — cProfile, py-spy
  • DB — EXPLAIN ANALYZE, pg_stat_statements

Flame Graph

Visual stack trace — wide function = most time। Bottleneck instant দেখা যায়।

Common Bottlenecks

  • N+1 query (most common)
  • Missing DB index
  • Synchronous I/O (use async)
  • Lock contention
  • Serialization overhead
  • Memory leak (long-running)
  • GC pressure

Optimization Mindset ⭐

  1. Measure first (profile)
  2. Fix biggest bottleneck
  3. Measure again
  4. Repeat
Premature optimization is the root of all evil — Donald Knuth

Caching Strategies

  • Cache-aside (lazy load)
  • Write-through
  • Write-behind (async)
  • Refresh-ahead
  • CDN edge cache
  • Application (Redis)
  • DB query cache

Chaos Engineering ⭐

Production-এ deliberate failure inject — resilience test।

Netflix Principles

  1. Define steady state
  2. Hypothesize কী হবে failure-এ
  3. Real-world events (server kill, network lag)
  4. Minimize blast radius
  5. Measure, learn, fix

Tools

  • Chaos Monkey (Netflix) — kill instance
  • Chaos Mesh — k8s
  • Gremlin — platform
  • Litmus — k8s open source
  • AWS Fault Injection Simulator

Game Day

Scheduled chaos — team practice incident response।

Performance Budget

Homepage budget:
  First Contentful Paint < 1.8s
  Largest Contentful Paint < 2.5s
  Total JS < 300KB
  Image < 500KB per page
  Lighthouse score > 90
// CI fail if exceeded

Web Performance ⭐

  • Core Web Vitals (LCP, FID, CLS)
  • Code split, lazy load
  • Tree shake, minify
  • Image optimize (WebP, AVIF)
  • HTTP/2, HTTP/3
  • CDN, brotli compression
  • Preload, prefetch, preconnect
  • Service Worker cache