Loading...
Loading...
When validating system performance under load, identifying bottlenecks through profiling, or optimizing application responsiveness. Covers load testing (k6, Locust), profiling (CPU, memory, I/O), and optimization strategies (caching, query optimization, Core Web Vitals). Use for capacity planning, regression detection, and establishing performance SLOs.
npx skill4agent add vuralserhat86/antigravity-agentic-skills performance_engineeringWhat am I trying to learn?
├─ Can my system handle expected traffic? → LOAD TEST
├─ What's the maximum capacity? → STRESS TEST
├─ Will it stay stable over time? → SOAK TEST
└─ Can it handle traffic spikes? → SPIKE TESTreferences/testing-types.mdbrew install k6 # macOS
sudo apt-get install k6 # Linuximport http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 20 },
{ duration: '30s', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/products');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}k6 run script.jsexamples/k6/pip install locustfrom locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
host = "https://api.example.com"
@task(3)
def view_products(self):
self.client.get("/products")
@task(1)
def view_product_detail(self):
self.client.get("/products/123")locust -f locustfile.py --headless -u 100 -r 10 --run-time 10mexamples/locust/| Symptom | Profiling Type | Tool |
|---|---|---|
| High CPU (>70%) | CPU Profiling | py-spy, pprof, DevTools |
| Memory growing | Memory Profiling | memory_profiler, pprof heap |
| Slow response, low CPU | I/O Profiling | Query logs, pprof block |
pip install py-spy
# Profile running process
py-spy record -o profile.svg --pid <PID> --duration 30
# Top-like view
py-spy top --pid <PID>from memory_profiler import profile
@profile
def my_function():
a = [1] * (10 ** 6)
return a
# Run: python -m memory_profiler script.pyimport (
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
startApp()
}# CPU profile (30 seconds)
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
# Interactive analysis
(pprof) top
(pprof) webnode --inspect app.js
# Open chrome://inspect
# Performance tab → Recordnpm install -g clinic
clinic doctor -- node app.jsreferences/profiling-guide.mdexamples/profiling/import redis
r = redis.Redis()
def get_cached_data(key, fn, ttl=300):
cached = r.get(key)
if cached:
return json.loads(cached)
data = fn()
r.setex(key, ttl, json.dumps(data))
return data# Bad: N+1 queries
users = User.query.all()
for user in users:
print(user.orders) # Separate query per user
# Good: Eager loading
users = User.query.options(joinedload(User.orders)).all()CREATE INDEX idx_users_email ON users(email);app.get('/api/products', async (req, res) => {
const { cursor, limit = 20 } = req.query;
const products = await db.query(
'SELECT * FROM products WHERE id > ? ORDER BY id LIMIT ?',
[cursor || 0, limit]
);
res.json({
data: products,
next_cursor: products[products.length - 1]?.id,
});
});references/optimization-strategies.mdreferences/frontend-performance.md| Service Type | p95 Latency | p99 Latency | Availability |
|---|---|---|---|
| User-Facing API | < 200ms | < 500ms | 99.9% |
| Internal API | < 100ms | < 300ms | 99.5% |
| Database Query | < 50ms | < 100ms | 99.99% |
| Background Job | < 5s | < 10s | 99% |
| Real-time API | < 50ms | < 100ms | 99.95% |
references/slo-framework.mdname: performance_engineering
on:
pull_request:
branches: [main]
jobs:
load-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install k6
run: |
curl https://github.com/grafana/k6/releases/download/v0.48.0/k6-v0.48.0-linux-amd64.tar.gz -L | tar xvz
sudo mv k6-v0.48.0-linux-amd64/k6 /usr/local/bin/
- name: Run load test
run: k6 run tests/load/api-test.js// k6 test with thresholds (fail build if violated)
export const options = {
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};references/testing-types.mdreferences/profiling-guide.mdreferences/testing-types.mdreferences/profiling-guide.mdreferences/optimization-strategies.mdreferences/frontend-performance.mdreferences/slo-framework.mdreferences/benchmarking.mdexamples/k6/examples/locust/examples/profiling/examples/optimization/testing-strategiesbuilding-ci-pipelinesinfrastructure-as-codeKaynak: k6 Methodology & The Art of Capacity Planning
| Aşama | Doğrulama |
|---|---|
| 1 | Test verisi (Database seed) yeterli hacimde mi? |
| 2 | Load Generator (Test makinesi) CPU darboğazına girdi mi? (False negative riski). |
| 3 | 3rd party API'lar (Stripe, Twilio) mock'landı mı? (Masraf ve ban riski). |