From 3823dd826cb272fe552f892641f562fbde12c9ed Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 17 May 2026 17:41:49 +0200 Subject: [PATCH] feat: Refactor stress test configuration for improved user ramp-up and limit analysis --- simulations/stressTest.js | 73 +++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/simulations/stressTest.js b/simulations/stressTest.js index ae60940..2bb8fb1 100644 --- a/simulations/stressTest.js +++ b/simulations/stressTest.js @@ -1,34 +1,63 @@ import { chessUserJourney } from '../scenarios/chessUserScenario.js'; import { thresholds } from '../config.js'; +import { Counter } from 'k6/metrics'; -const START_USERS = parseInt(__ENV.START_USERS || '2', 10); -const USERS_INCREMENT = parseInt(__ENV.USERS_INCREMENT || '2', 10); -const STEPS = parseInt(__ENV.STEPS || '2', 10); -const STEP_DURATION = parseInt(__ENV.STEP_DURATION || '30', 10); -const RAMP_DURATION = parseInt(__ENV.RAMP_DURATION || '10', 10); +const START_USERS = parseInt(__ENV.START_USERS || '1', 10); +const MAX_USERS = parseInt(__ENV.MAX_USERS || '100', 10); +const RAMP_DURATION = parseInt(__ENV.RAMP_DURATION || '300', 10); -const stages = []; -let currentUsers = START_USERS; - -for (let i = 0; i < STEPS; i++) { - // Ramp up - stages.push({ - duration: `${RAMP_DURATION}s`, - target: currentUsers, - }); - // Hold at level - stages.push({ - duration: `${STEP_DURATION}s`, - target: currentUsers, - }); - currentUsers += USERS_INCREMENT; -} +const userLimitCounter = new Counter('user_limit_tracker'); export const options = { - stages, + stages: [ + { + duration: `${RAMP_DURATION}s`, + target: MAX_USERS, + }, + ], thresholds, }; export default function () { chessUserJourney(); + userLimitCounter.add(1); +} + +export function handleSummary(data) { + const metrics = data.metrics; + + // Find breaking point by analyzing metrics over time + let breakingPointUsers = START_USERS; + let maxSuccessfulUsers = START_USERS; + + // Check final threshold results + const summaryText = JSON.stringify(data.metrics, null, 2); + + // Calculate estimated limit based on error rates + if (metrics['http_req_failed']) { + const failedReqs = metrics['http_req_failed'].values.count || 0; + const totalReqs = metrics['http_reqs']?.values.count || 1; + const failureRate = (failedReqs / totalReqs) * 100; + + // Estimate breaking point based on load curve + const timeElapsed = RAMP_DURATION; + const usersPerSecond = MAX_USERS / timeElapsed; + const estimatedBreakingPoint = Math.floor((failureRate / 100) * MAX_USERS); + + if (estimatedBreakingPoint > 0) { + maxSuccessfulUsers = Math.max(estimatedBreakingPoint - 1, START_USERS); + } + } + + // Print summary + console.log(''); + console.log('=== STRESS TEST LIMIT ANALYSIS ==='); + console.log(`Test Duration: ${RAMP_DURATION}s`); + console.log(`Ramp Range: ${START_USERS} → ${MAX_USERS} users`); + console.log(`Estimated System Limit: ${maxSuccessfulUsers} concurrent users`); + console.log(''); + + return { + stdout: summaryText, + }; }