Skip to content

Commit

Permalink
test: switch back to reader time
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq authored and karenc-bq committed Nov 1, 2024
1 parent 0ae7f59 commit a5b77ed
Showing 1 changed file with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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`,
Expand All @@ -109,14 +111,16 @@ describe("rwperformance", () => {
await PerfTestUtility.connectWithRetry(client);
await client.setReadOnly(true);
await client.setReadOnly(false);
await client.end();
}
}

const rwPluginWithPoolWithWarmUpData = await measurePerformance(rwPluginWithPoolConfig);

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`,
Expand Down Expand Up @@ -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;
Expand All @@ -168,10 +187,13 @@ function initReadWritePluginConfig(host: string, port: number) {

async function measurePerformance(config: any): Promise<Result> {
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++) {
Expand Down Expand Up @@ -207,6 +229,19 @@ async function measurePerformance(config: any): Promise<Result> {
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();
}
Expand All @@ -233,6 +268,16 @@ async function measurePerformance(config: any): Promise<Result> {
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;
}

Expand All @@ -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 {
Expand Down

0 comments on commit a5b77ed

Please sign in to comment.