From ac5de5ea048f936976e567135a9d1465eea0ae49 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 4 Mar 2024 16:23:21 +0200 Subject: [PATCH 1/6] test commit --- k6/compare-results.js | 1 + 1 file changed, 1 insertion(+) diff --git a/k6/compare-results.js b/k6/compare-results.js index 3ea3e0b..00b31ee 100644 --- a/k6/compare-results.js +++ b/k6/compare-results.js @@ -112,3 +112,4 @@ const targetMetricsPath = process.argv[5]; const outputPath = process.argv[6]; generateComparisonTable(baseCommitHash, baseMetricsPath, targetCommitHash, targetMetricsPath, outputPath); + From 7798c43db2dff0c3dcc2fd86066451296fa027ce Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 4 Mar 2024 16:28:16 +0200 Subject: [PATCH 2/6] fix color --- k6/compare-results.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/k6/compare-results.js b/k6/compare-results.js index 00b31ee..6deb6e6 100644 --- a/k6/compare-results.js +++ b/k6/compare-results.js @@ -86,12 +86,11 @@ function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { } function getColor(baseValue, targetValue) { - if (baseValue > targetValue) { - return '✅'; // Green emoji for improvement - } else if (baseValue > targetValue) { + if (baseValue >= targetValue) { + return '✅'; // Green emoji for improvement or equivalence + } else { return '🔴'; // Red emoji for degradation } - return ''; } function getDifferencePercentage(baseValue, targetValue) { From 9b130b04de2c7ff07b1d8901718b6f37aa34b07f Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 4 Mar 2024 16:33:45 +0200 Subject: [PATCH 3/6] fix color --- apps/api/src/endpoints/tokens/token.service.ts | 4 +++- apps/api/src/endpoints/users/user.service.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/api/src/endpoints/tokens/token.service.ts b/apps/api/src/endpoints/tokens/token.service.ts index 9cd5adc..1aa99a4 100644 --- a/apps/api/src/endpoints/tokens/token.service.ts +++ b/apps/api/src/endpoints/tokens/token.service.ts @@ -15,6 +15,8 @@ export class TokenService { } async findAll(): Promise { - return await this.tokenModel.find().exec(); + await Promise.resolve(); + return []; // return directly so the results should look better in performance benchmarks + //return await this.tokenModel.find().exec(); } } diff --git a/apps/api/src/endpoints/users/user.service.ts b/apps/api/src/endpoints/users/user.service.ts index a6df6bd..2e9d85a 100644 --- a/apps/api/src/endpoints/users/user.service.ts +++ b/apps/api/src/endpoints/users/user.service.ts @@ -20,6 +20,7 @@ export class UsersService { } async findAll(): Promise { + await new Promise((resolve) => setTimeout(resolve, 500)); // introduced a delay so we can see performance degradation return await this.usersRepository.find(); } From 7beef016bd05c0af522f61bdad3ca9ccd3bf1615 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 4 Mar 2024 16:55:38 +0200 Subject: [PATCH 4/6] less decimals --- k6/compare-results.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/k6/compare-results.js b/k6/compare-results.js index 6deb6e6..4a30799 100644 --- a/k6/compare-results.js +++ b/k6/compare-results.js @@ -72,10 +72,10 @@ function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { const p95Color = getColor(baseP95, targetP95); table += `| **${key}** | | |\n`; - table += `| - Average Response Time | ${baseAvg} ms | ${targetAvg} ms | ${avgDiff} ${avgColor} |\n`; - table += `| - Max Response Time | ${baseMax} ms | ${targetMax} ms | ${maxDiff} ${maxColor} |\n`; - table += `| - 90th Percentile | ${baseP90} ms | ${targetP90} ms | ${p90Diff} ${p90Color} |\n`; - table += `| - 95th Percentile | ${baseP95} ms | ${targetP95} ms | ${p95Diff} ${p95Color} |\n`; + table += `| - Average Response Time | ${baseAvg.toFixed(2)} ms | ${targetAvg.toFixed(2)} ms | ${avgDiff} ${avgColor} |\n`; + table += `| - Max Response Time | ${baseMax.toFixed(2)} ms | ${targetMax.toFixed(2)} ms | ${maxDiff} ${maxColor} |\n`; + table += `| - 90th Percentile | ${baseP90.toFixed(2)} ms | ${targetP90.toFixed(2)} ms | ${p90Diff} ${p90Color} |\n`; + table += `| - 95th Percentile | ${baseP95.toFixed(2)} ms | ${targetP95.toFixed(2)} ms | ${p95Diff} ${p95Color} |\n`; } const baseDuration = baseData['Test Run Duration'].toFixed(2); From 1c4171ae590b68ad4950bccec0fc8bed23b5eef6 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Fri, 8 Mar 2024 16:26:45 +0200 Subject: [PATCH 5/6] update table --- k6/compare-results.js | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/k6/compare-results.js b/k6/compare-results.js index 4a30799..3ae08be 100644 --- a/k6/compare-results.js +++ b/k6/compare-results.js @@ -44,9 +44,10 @@ function extractMetrics(metrics) { } function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { - let table = `k6 load testing comparison.\nBase Commit Hash: ${baseCommitHash}\nTarget Commit Hash: ${targetCommitHash}\n\n`; - table += '| Metric | Base | Target | Diff |\n'; - table += '| ------ | ---- | ------ | ---- |\n'; + let table = `k6 load testing comparison.\nBase Commit Hash: ${baseCommitHash}\nTarget Commit Hash: ${targetCommitHash}\n`; + table += `Test duration: ${baseData['Test Run Duration'].toFixed(2)} ms (base)| targetData['Test Run Duration'].toFixed(2) ms (target) \n\n`; + table += '| Endpoint \ Metric | Average | Max | p(90) | p(95) |\n'; + table += '| ----------------- | ---- | ------ | ----- | ----- |\n'; for (const key of Object.keys(baseData)) { if (key === 'Test Run Duration') { @@ -61,27 +62,9 @@ function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { const baseP95 = baseData[key].p95; const targetP95 = targetData[key].p95; - const avgDiff = getDifferencePercentage(baseAvg, targetAvg); - const maxDiff = getDifferencePercentage(baseMax, targetMax); - const p90Diff = getDifferencePercentage(baseP90, targetP90); - const p95Diff = getDifferencePercentage(baseP95, targetP95); - - const avgColor = getColor(baseAvg, targetAvg); - const maxColor = getColor(baseMax, targetMax); - const p90Color = getColor(baseP90, targetP90); - const p95Color = getColor(baseP95, targetP95); - - table += `| **${key}** | | |\n`; - table += `| - Average Response Time | ${baseAvg.toFixed(2)} ms | ${targetAvg.toFixed(2)} ms | ${avgDiff} ${avgColor} |\n`; - table += `| - Max Response Time | ${baseMax.toFixed(2)} ms | ${targetMax.toFixed(2)} ms | ${maxDiff} ${maxColor} |\n`; - table += `| - 90th Percentile | ${baseP90.toFixed(2)} ms | ${targetP90.toFixed(2)} ms | ${p90Diff} ${p90Color} |\n`; - table += `| - 95th Percentile | ${baseP95.toFixed(2)} ms | ${targetP95.toFixed(2)} ms | ${p95Diff} ${p95Color} |\n`; + table += `| **${key}** | ${computeCell(baseAvg, targetAvg)} | ${computeCell(baseMax, targetMax)} | ${computeCell(baseP90, targetP90)} | ${computeCell(baseP95, targetP95)} | \n`; } - const baseDuration = baseData['Test Run Duration'].toFixed(2); - const targetDuration = targetData['Test Run Duration'].toFixed(2); - table += `| **Test Run Duration** | ${baseDuration} ms | ${targetDuration} ms | |\n`; - return table; } @@ -93,10 +76,21 @@ function getColor(baseValue, targetValue) { } } +function computeCell(baseDuration, targetDuration) { + return `${baseDuration.toFixed(2)} ms -> ${targetDuration.toFixed(2)} ms (${getDifferencePercentage(baseDuration, targetDuration)})`; +} + function getDifferencePercentage(baseValue, targetValue) { const difference = ((targetValue - baseValue) / baseValue) * 100; const sign = difference >= 0 ? '+' : ''; - return `${sign}${difference.toFixed(2)}%`; + let output = `${sign}${difference.toFixed(2)}%`; + if (difference > 20.0) { + output += ' ⚠️'; + } else if (difference < -20) { + output += ' 🟢'; + } + + return `${output}`; } if (process.argv.length !== 7) { From d8e2e44c25a357d06a8c03de579e89f9fa01b6be Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Fri, 8 Mar 2024 16:55:17 +0200 Subject: [PATCH 6/6] fix --- k6/compare-results.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/k6/compare-results.js b/k6/compare-results.js index 3ae08be..3a9ba30 100644 --- a/k6/compare-results.js +++ b/k6/compare-results.js @@ -45,9 +45,9 @@ function extractMetrics(metrics) { function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { let table = `k6 load testing comparison.\nBase Commit Hash: ${baseCommitHash}\nTarget Commit Hash: ${targetCommitHash}\n`; - table += `Test duration: ${baseData['Test Run Duration'].toFixed(2)} ms (base)| targetData['Test Run Duration'].toFixed(2) ms (target) \n\n`; - table += '| Endpoint \ Metric | Average | Max | p(90) | p(95) |\n'; - table += '| ----------------- | ---- | ------ | ----- | ----- |\n'; + table += `Test duration: ${baseData['Test Run Duration'].toFixed(2)} ms (base) | ${targetData['Test Run Duration'].toFixed(2)} ms (target) \n\n`; + table += '| Endpoint \\ Metric | Average | Max | p(90) | p(95) |\n'; + table += '| ------------------ | ---- | ------ | ----- | ----- |\n'; for (const key of Object.keys(baseData)) { if (key === 'Test Run Duration') { @@ -68,14 +68,6 @@ function generateTable(baseCommitHash, baseData, targetCommitHash, targetData) { return table; } -function getColor(baseValue, targetValue) { - if (baseValue >= targetValue) { - return '✅'; // Green emoji for improvement or equivalence - } else { - return '🔴'; // Red emoji for degradation - } -} - function computeCell(baseDuration, targetDuration) { return `${baseDuration.toFixed(2)} ms -> ${targetDuration.toFixed(2)} ms (${getDifferencePercentage(baseDuration, targetDuration)})`; }