From 3fd626c8d2af5a2b6b72738712f554a22035dd73 Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Thu, 19 Sep 2024 11:46:21 -0400 Subject: [PATCH] properly count steps of flows in benchmark (#4407) * fix(benchmark): properly count steps of flows * signing commit --------- Co-authored-by: Alexander Petric --- benchmarks/benchmark_oneoff.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/benchmarks/benchmark_oneoff.ts b/benchmarks/benchmark_oneoff.ts index da8c8b9fea..24ba4e2c13 100644 --- a/benchmarks/benchmark_oneoff.ts +++ b/benchmarks/benchmark_oneoff.ts @@ -106,6 +106,30 @@ export async function main({ ).database_length; } + async function getFlowStepCount( + workspace: string, + path: string + ): Promise { + const response = await fetch( + `${config.server}/api/w/${workspace}/flows/get/${path}`, + { headers: { ["Authorization"]: "Bearer " + config.token } } + ); + + const data = await response.json(); + let stepCount = 0; + + for (const mod of data.value.modules) { + if (mod.value.type === "flow" && mod.value.path) { + const subFlowCount = await getFlowStepCount(workspace, mod.value.path); + stepCount += subFlowCount; + } else { + stepCount += 1; + } + } + + return stepCount; + } + let pastJobs = 0; async function getCompletedJobsCount(): Promise { const completedJobs = ( @@ -133,6 +157,7 @@ export async function main({ console.log(`Bulk creating ${jobsSent} jobs`); const start_create = Date.now(); + let nStepsFlow = 0; let body: string; if (kind === "noop") { body = JSON.stringify({ @@ -148,6 +173,7 @@ export async function main({ path: "f/benchmarks/" + kind, }); } else if (["2steps"].includes(kind)) { + nStepsFlow = 2; const payload = getFlowPayload(kind); body = JSON.stringify({ kind: "flow", @@ -155,9 +181,12 @@ export async function main({ }); } else if (kind.startsWith("flow:")) { console.log("Detected custom flow "); + let flow_path = kind.substr(5); + nStepsFlow = await getFlowStepCount(config.workspace_id, flow_path); + console.log(`Total steps of flow including sub-flows: ${nStepsFlow}`); body = JSON.stringify({ kind: "flow", - path: kind.substr(5), + path: flow_path, }); } else if (kind.startsWith("script:")) { console.log("Detected custom script"); @@ -218,7 +247,7 @@ export async function main({ const elapsed = start ? Date.now() - start : 0; completedJobs = await getCompletedJobsCount(); if (kind === "2steps" || kind.startsWith("flow:")) { - completedJobs = Math.floor(completedJobs / 3); + completedJobs = Math.floor(completedJobs / (nStepsFlow + 1)); } const avgThr = ((completedJobs / elapsed) * 1000).toFixed(2); const instThr =