diff --git a/tests/integration/container/tests/read_write_splitting_performance.test.ts b/tests/integration/container/tests/read_write_splitting_performance.test.ts index d371e4af..e07c23f5 100644 --- a/tests/integration/container/tests/read_write_splitting_performance.test.ts +++ b/tests/integration/container/tests/read_write_splitting_performance.test.ts @@ -65,9 +65,10 @@ describe("rwperformance", () => { const rwPluginData = await measurePerformance(rwPluginConfig); let readerData = calculateReaderOverhead("Switch to reader", rwPluginData, noPluginData); - let writerData = calculateWriterOverhead("Switch to writer (using cached connection", rwPluginData, noPluginData); + let writerData = calculateWriterOverhead("Switch to writer (using cached connection)", rwPluginData, noPluginData); + let readerCacheData = calculateReaderCacheOverhead("Switch to reader (using cached connection)", rwPluginData, noPluginData); - setReadOnlyPerfDataList.push(readerData, writerData); + setReadOnlyPerfDataList.push(readerData, writerData, readerCacheData); PerfTestUtility.writePerfDataToFile( setReadOnlyPerfDataList, `ReadWriteSplittingPerformanceResults_${env.engine}_Instances_${env.instances.length}_SwitchReaderWriterConnection.xlsx`, @@ -83,7 +84,8 @@ describe("rwperformance", () => { readerData = calculateReaderOverhead("Switch to reader", rwPluginWithPoolData, noPluginData); writerData = calculateWriterOverhead("Switch to writer (using cached connection)", rwPluginWithPoolData, noPluginData); - setReadOnlyPerfDataList.push(readerData, writerData); + readerCacheData = calculateReaderCacheOverhead("Switch to reader (using cached connection)", rwPluginWithPoolData, noPluginData); + setReadOnlyPerfDataList.push(readerData, writerData, readerCacheData); PerfTestUtility.writePerfDataToFile( setReadOnlyPerfDataList, `ReadWriteSplittingPerformanceResults_${env.engine}_Instances_${env.instances.length}_SwitchReaderWriterConnection.xlsx`, @@ -109,6 +111,7 @@ describe("rwperformance", () => { await PerfTestUtility.connectWithRetry(client); await client.setReadOnly(true); await client.setReadOnly(false); + await client.end(); } } @@ -116,7 +119,8 @@ describe("rwperformance", () => { readerData = calculateReaderOverhead("Switch to reader", rwPluginWithPoolWithWarmUpData, noPluginData); writerData = calculateWriterOverhead("Switch to writer (using cached connection)", rwPluginWithPoolWithWarmUpData, noPluginData); - setReadOnlyPerfDataList.push(readerData, writerData); + readerCacheData = calculateReaderCacheOverhead("Switch to reader (using cached connection)", rwPluginWithPoolWithWarmUpData, noPluginData); + setReadOnlyPerfDataList.push(readerData, writerData, readerCacheData); PerfTestUtility.writePerfDataToFile( setReadOnlyPerfDataList, `ReadWriteSplittingPerformanceResults_${env.engine}_Instances_${env.instances.length}_SwitchReaderWriterConnection.xlsx`, @@ -145,6 +149,21 @@ function calculateReaderOverhead(connectionSwitch: string, data1: Result, data2: ); } +function calculateReaderCacheOverhead(connectionSwitch: string, data1: Result, data2: Result): PerfStatSwitchConnection { + const switchToReaderCachedMinOverhead = data1.switchToReaderCachedMin - data2.switchToReaderCachedMin; + const switchToReaderCachedMaxOverhead = data1.switchToReaderCachedMax - data2.switchToReaderCachedMax; + const switchToReaderCachedAvgOverhead = data1.switchToReaderCachedAvg - data2.switchToReaderCachedAvg; + const switchToReaderCachedWithConnectTime = data1.switchToReaderCachedWithConnectTime - data2.switchToReaderCachedWithConnectTime; + + return new PerfStatSwitchConnection( + connectionSwitch, + switchToReaderCachedMinOverhead, + switchToReaderCachedMaxOverhead, + switchToReaderCachedAvgOverhead, + switchToReaderCachedWithConnectTime + ); +} + function calculateWriterOverhead(connectionSwitch: string, data1: Result, data2: Result) { const switchToWriterMinOverhead = data1.switchToWriterMin - data2.switchToWriterMin; const switchToWriterMaxOverhead = data1.switchToWriterMax - data2.switchToWriterMax; @@ -168,10 +187,13 @@ function initReadWritePluginConfig(host: string, port: number) { async function measurePerformance(config: any): Promise { let switchToReaderStartTime; + let switchToReaderCachedStartTime; let switchToWriterStartTime; const elapsedSwitchToReaderTimeNanos: bigint[] = []; + const elapsedSwitchToReaderCachedTimeNanos: bigint[] = []; const elapsedSwitchToWriterTimeNanos: bigint[] = []; const elapsedSwitchToReaderWithConnectTimeNanos: bigint[] = []; + const elapsedSwitchToReaderCachedWithConnectTimeNanos: bigint[] = []; const elapsedSwitchToWriterWithConnectTimeNanos: bigint[] = []; for (let i = 0; i < REPEAT_TIMES; i++) { @@ -207,6 +229,19 @@ async function measurePerformance(config: any): Promise { const time2 = getTimeInNanos() - switchToWriterStartTime; elapsedSwitchToWriterTimeNanos.push(time2 - connectTime - executionTime); elapsedSwitchToWriterWithConnectTimeNanos.push(time2 - executionTime); + + // Calculate time required to switch to an existing reader connection. + ConnectTimePlugin.resetConnectTime(); + ExecuteTimePlugin.resetExecuteTime(); + + switchToReaderCachedStartTime = getTimeInNanos(); + await client.setReadOnly(true); + + connectTime = ConnectTimePlugin.getTotalConnectTime(); + executionTime = ExecuteTimePlugin.getTotalExecuteTime(); + const time3 = getTimeInNanos() - switchToReaderCachedStartTime; + elapsedSwitchToReaderCachedTimeNanos.push(time3 - connectTime - executionTime); + elapsedSwitchToReaderCachedWithConnectTimeNanos.push(time3 - executionTime); } finally { await client.end(); } @@ -233,6 +268,16 @@ async function measurePerformance(config: any): Promise { return sum + value; }, 0n) / BigInt(elapsedSwitchToWriterWithConnectTimeNanos.length); + [min, max, sum] = calculateStats(elapsedSwitchToReaderCachedTimeNanos); + avg = sum / BigInt(elapsedSwitchToReaderCachedTimeNanos.length); + data.switchToReaderCachedMin = min; + data.switchToReaderCachedMax = max; + data.switchToReaderCachedAvg = avg; + data.switchToReaderCachedWithConnectTime = + elapsedSwitchToReaderCachedTimeNanos.reduce((sum, value) => { + return sum + value; + }, 0n) / BigInt(elapsedSwitchToReaderCachedWithConnectTimeNanos.length); + return data; } @@ -259,6 +304,11 @@ class Result { switchToWriterMax: bigint = 0n; switchToWriterAvg: bigint = 0n; switchToWriterWithConnectTime: bigint = 0n; + + switchToReaderCachedMin: bigint = 0n; + switchToReaderCachedMax: bigint = 0n; + switchToReaderCachedAvg: bigint = 0n; + switchToReaderCachedWithConnectTime: bigint = 0n; } class PerfStatSwitchConnection implements PerfStat {