Performance — Đo lường hiệu suất

Load testing, benchmarking, và profiling để đảm bảo hệ thống đáp ứng performance requirements.

Cú pháp

/benchmark                         # Load testing + performance benchmarking
/profile                           # Performance profiling chi tiết

Bảng tham chiếu nhanh

LệnhMô tảOutput
/benchmarkLoad test với scenarios tự độngThroughput, latency, error rate
/profileProfiling chi tiết (CPU, memory, I/O)Bottleneck identification + recommendations

/benchmark — Load Testing

1

Bước 1: Generate scenarios

Tạo test scenarios dựa trên API endpoints và user flows.
2

Bước 2: Execute load test

Chạy với multiple concurrency levels (10, 50, 100, 500 users).
3

Bước 3: Collect metrics

Thu thập: requests/sec, p50/p95/p99 latency, error rate, throughput.
4

Bước 4: Analyze + Report

Identify bottlenecks, suggest optimizations.

/profile — Performance Profiling

/profile                           # Profile application
Phân tích:
  • CPU usage per function
  • Memory allocation patterns
  • Database query performance (N+1 detection)
  • Network I/O bottlenecks

Ví dụ thực tế

BENCHMARK RESULTS
├── Endpoint: GET /api/v1/products
├── Concurrency: 100 users
├── Duration: 60 seconds
├── Metrics:
│   ├── Requests/sec:  450
│   ├── p50 latency:   45ms
│   ├── p95 latency:   180ms
│   ├── p99 latency:   520ms ⚠️
│   ├── Error rate:    0.2%
│   └── Throughput:    12.5 MB/s
└── BOTTLENECK: 
    └── products query — full table scan on 500K rows
        FIX: Add index on (category_id, created_at)

Performance Thresholds

MetricTargetAlert
p95 Latency< 200ms> 500ms
Error Rate< 0.1%> 1%
Requests/sec> 500< 100
Memory< 512MB> 1GB
CPU< 70%> 90%

Khi nào dùng / không dùng

DùngKhông dùng
Trước deploy productionDevelopment/staging chưa stable
Sau thay đổi database schemaMicro-optimization sớm
SLA review, capacity planningDebug specific slow endpoint (dùng /debug)