diff --git a/.github/workflows/integration-tests-command.yml b/.github/workflows/integration-tests-command.yml index 3855f91aa5..dd8cba6f65 100644 --- a/.github/workflows/integration-tests-command.yml +++ b/.github/workflows/integration-tests-command.yml @@ -1492,7 +1492,6 @@ jobs: APPSMITH_DISABLE_TELEMETRY: true POSTGRES_PASSWORD: postgres NODE_TLS_REJECT_UNAUTHORIZED: "0" - MACHINE: ${{matrix.machine}} run: ./start-test.sh # Restore the previous built bundle if present. If not push the newly built into the cache diff --git a/app/client/perf/src/ci/supabase.js b/app/client/perf/src/ci/supabase.js index b9c7adc64c..d681a1251a 100644 --- a/app/client/perf/src/ci/supabase.js +++ b/app/client/perf/src/ci/supabase.js @@ -79,7 +79,7 @@ const createRunMeta = async () => { pull_request_id: prId || parsePullRequestId(process.env.GITHUB_REF), runner_name: process.env?.RUNNER_NAME, host_name: hostname, - machine: process.env?.MACHINE || "", + machine: process.env?.MACHINE || "buildjet-4vcpu-ubuntu-2004", // Hardcoded temporarily. Should be removed }, ]); if (data) { diff --git a/app/client/perf/src/perf.js b/app/client/perf/src/perf.js index 2ec1aa8b62..f8bead5bd3 100644 --- a/app/client/perf/src/perf.js +++ b/app/client/perf/src/perf.js @@ -10,6 +10,12 @@ const { login, sortObjectKeys, } = require("./utils/utils"); + +const { + cleanTheHost, + setChromeProcessPriority, +} = require("./utils/system-cleanup"); + const selectors = { appMoreIcon: "span.t--options-icon", workspaceImportAppOption: '[data-cy*="t--workspace-import-app"]', @@ -17,6 +23,7 @@ const selectors = { importButton: '[data-cy*="t--workspace-import-app-button"]', createNewApp: ".createnew", }; + module.exports = class Perf { constructor(launchOptions = {}) { this.launchOptions = { @@ -62,9 +69,12 @@ module.exports = class Perf { * Launches the browser and, gives you the page */ launch = async () => { + await cleanTheHost(); this.browser = await puppeteer.launch(this.launchOptions); const pages_ = await this.browser.pages(); this.page = pages_[0]; + + await setChromeProcessPriority(); await this._login(); }; @@ -75,13 +85,20 @@ module.exports = class Perf { startTrace = async (action = "foo") => { if (this.currentTrace) { - console.warn("Trace progress. You can run only one trace at a time"); + console.warn( + "Trace already in progress. You can run only one trace at a time", + ); return; } this.currentTrace = action; await delay(3000, `before starting trace ${action}`); + await this.page._client.send("HeapProfiler.enable"); + await this.page._client.send("HeapProfiler.collectGarbage"); + await delay(1000, `After clearing memory`); + const path = `${APP_ROOT}/traces/${action}-${getFormattedTime()}-chrome-profile.json`; + await this.page.tracing.start({ path: path, screenshots: true, @@ -109,7 +126,7 @@ module.exports = class Perf { await this.page.waitForNavigation(); const currentUrl = this.page.url(); - const pageId = currentURL + const pageId = currentUrl .split("/")[5] ?.split("-") .pop(); diff --git a/app/client/perf/src/utils/system-cleanup.js b/app/client/perf/src/utils/system-cleanup.js new file mode 100644 index 0000000000..9a29f27bef --- /dev/null +++ b/app/client/perf/src/utils/system-cleanup.js @@ -0,0 +1,53 @@ +const cp = require("child_process"); + +exports.cleanTheHost = async () => { + await cp.exec("pidof chrome", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`Killing chrome processes: ${stdout}`); + stdout.split(" ").forEach((PID) => { + cp.exec(`sudo kill -9 ${PID}`, (error, stdout, stder) => { + if (error) { + console.log(`Kill error: ${error.message}`); + return; + } + if (stderr) { + console.log(`Kill stderr: ${stderr}`); + return; + } + if (stdout) { + console.log(`Kill stdout: ${stdout}`); + return; + } + }); + }); + }); + + // Clear OS caches + await cp.exec("sync; echo 3 | sudo tee /proc/sys/vm/drop_caches"); +}; + +exports.setChromeProcessPriority = async () => { + await cp.exec("pidof chrome", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: setting priority: ${stdout}`); + + // Set priority of chrome processes to maximum + stdout.split(" ").forEach((PID) => { + cp.execSync(`sudo renice -20 ${PID}`); + }); + }); +};