Skip to content

HabitaNexus/monorepo / skills/system-reliability-engineering/load-testing-performance

load-testing-performance

Unverified

scripts/k6/rust-api-load.js

View on GitHub
/**
 * k6 Load Test for Rust API
 *
 * Optimized load test for Rust backend APIs.
 * Expects lower latency due to Rust performance.
 *
 * Usage:
 *   k6 run rust-api-load.js
 *   k6 run rust-api-load.js --env BASE_URL=http://localhost:8080
 */

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

const errorRate = new Rate('errors');
const requestDuration = new Trend('request_duration');

export const options = {
  stages: [
    { duration: '2m', target: 100 },
    { duration: '5m', target: 100 },
    { duration: '2m', target: 200 },
    { duration: '5m', target: 200 },
    { duration: '2m', target: 0 },
  ],
  thresholds: {
    http_req_duration: ['p(95)<50', 'p(99)<100'], // Rust should be faster
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const baseUrl = __ENV.BASE_URL || 'http://localhost:8080';

  // Test health endpoint
  const healthCheck = http.get(`${baseUrl}/health`, {
    tags: { name: 'HealthCheck' },
  });
  check(healthCheck, {
    'health check status 200': (r) => r.status === 200,
  });

  // Test API endpoint
  const startTime = Date.now();
  const response = http.get(`${baseUrl}/api/users`, {
    headers: {
      'Content-Type': 'application/json',
    },
    tags: { name: 'GetUsers' },
  });

  const duration = Date.now() - startTime;

  const success = check(response, {
    'status is 200': (r) => r.status === 200,
    'response time < 50ms': (r) => r.timings.duration < 50,
    'has users': (r) => {
      try {
        const data = JSON.parse(r.body);
        return data.users && data.users.length > 0;
      } catch {
        return false;
      }
    },
  });

  errorRate.add(!success);
  requestDuration.add(duration);

  sleep(1);
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall