Skip to content

Commit

Permalink
[Service Bus] Perf tests with the framework (Azure#12993)
Browse files Browse the repository at this point in the history
### New perf folder
- The new "perf" folder uses the perf framework. 
- With the perf framework, only the send test can be written. 
- This PR adds the send test for track 1 and track 2.
- This would be useful in comparing track 1 and track 2, as well as for the cross-language comparisons.
- The track-2 tests depend on the current code on master and would require updates if the source code changes.

#### To execute the track 2 tests

1. Build the service-bus package `rush build -t service-bus`.
2. Navigate to `service-bus` folder `cd sdk\servicebus\service-bus\`.
3. Create a service-bus namespace and populate the .env file at `servicebus\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` variables.
4. Run the tests as follows
   - batch send
     - `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`
#### To execture the track 1 tests

1. Navigate to `test-utils\perfstress` folder `cd sdk\test-utils\perfstress\`
2. Build the package `rush update && rush build -t test-utils-perfstress`
3. Pack the perf package `rushx pack`
4. Navigate to `service-bus\perf\track-1` folder `cd sdk\servicebus\service-bus\perf\track-1`.
5. Install the perf package `npm i ..\..\..\..\..\test-utils\perfstress\azure-test-utils-perfstress-1.0.0.tgz`
6. Run `npm install` to get `service-bus V1`.
7. Create a service-bus namespace and a queue with default options. Populate the .env file at `servicebus\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` and `QUEUE_NAME` variables.
8. Run the tests as follows
   - batch send
     - `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`

### Existing perf tests
- There is an existing "perf" folder with the tests for send and receive for `azure-sb`, `rhea-promise`, `service-bus-v1`, and `service-bus-v7` libraries.
- These tests show the memory consumption too in the report. They do not use the perf framework. (And the perf framework isn't yet capable of handling the receive scenarios.)
- Retaining the existing tests for the above reasons.
- This PR renames the "perf" folder(with existing tests) to "perf-js-libs".
  • Loading branch information
HarshaNalluru authored Jan 29, 2021
1 parent 230fd72 commit e15c042
Show file tree
Hide file tree
Showing 27 changed files with 225 additions and 3 deletions.
3 changes: 2 additions & 1 deletion eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ omitted_paths:
- sdk/search/*/test/README.md
- sdk/servicebus/*/test/README.md
- sdk/servicebus/README.md
- sdk/servicebus/service-bus/test/perf/service-bus-*
- sdk/servicebus/service-bus/test/perf-js-libs/service-bus-*
- sdk/servicebus/service-bus/test/perf/**
- sdk/servicebus/service-bus/test/stress/*
- sdk/schemaregistry/README.md
- sdk/storage/*/test/README.md
Expand Down
2 changes: 2 additions & 0 deletions sdk/servicebus/service-bus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o service-bus-lintReport.html || exit 0",
"pack": "npm pack 2>&1",
"perf-test:node": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" ts-node test/perf/track-2/index.spec.ts",
"prebuild": "npm run clean",
"test:browser": "npm run clean && npm run build:test:browser && npm run integration-test:browser",
"test:node": "npm run clean && npm run build:test:node && npm run integration-test:node",
Expand Down Expand Up @@ -117,6 +118,7 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^1.1.0",
"@azure/test-utils-perfstress": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-inject": "^4.0.0",
Expand Down
6 changes: 5 additions & 1 deletion sdk/servicebus/service-bus/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export function nodeConfig({ test = false, production = false } = {}) {

if (test) {
// entry point is every test file
baseConfig.input = "dist-esm/test/**/*.spec.js";
baseConfig.input = [
"dist-esm/service-bus/test/internal/*.spec.js",
"dist-esm/service-bus/test/node/*.spec.js",
"dist-esm/service-bus/test/*.spec.js"
];
baseConfig.plugins.unshift(multiEntry({ exports: false }));

// different output file
Expand Down
12 changes: 12 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Guide

1. Navigate to `test-utils\perfstress` folder `cd sdk\test-utils\perfstress\`
2. Build the package `rush update && rush build -t test-utils-perfstress`
3. Pack the perf package `rushx pack`
4. Navigate to `service-bus\perf\track-1` folder `cd sdk\servicebus\service-bus\perf\track-1`.
5. Install the perf package `npm i ..\..\..\..\..\test-utils\perfstress\azure-test-utils-perfstress-1.0.0.tgz`
6. Run `npm install` to get `service-bus V1`.
7. Create a service-bus namespace and populate the .env file at `servicebus\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` and `QUEUE_NAME` variables.
8. Run the tests as follows
- batch send
- `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`
11 changes: 11 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
import { BatchSendTest } from "./sendBatch.spec";

console.log("=== Starting the perfStress test ===");

const perfStressProgram = new PerfStressProgram(selectPerfStressTest([BatchSendTest]));

perfStressProgram.run();
16 changes: 16 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "track-1",
"version": "1.0.0",
"description": "1. Build the service-bus package `rush build -t service-bus`. 2. Navigate to `service-bus` folder `cd sdk\\servicebus\\service-bus\\`. 3. Create a service-bus namespace and populate the .env file at `servicebus\\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` variables. 4. Run the tests as follows",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@azure/service-bus": "^1.1.10",
"@azure/test-utils-perfstress": "file:../../../../../test-utils/perfstress/azure-test-utils-perfstress-1.0.0.tgz"
},
"scripts": {
"perf-test:node": "ts-node index.spec.ts"
}
}
26 changes: 26 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/sbBase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest, getEnvVar } from "@azure/test-utils-perfstress";
import { ServiceBusClient } from "@azure/service-bus";

// Expects the .env file at the same level as the "test" folder
import * as dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

const connectionString = getEnvVar("SERVICEBUS_CONNECTION_STRING");
const sbClient = ServiceBusClient.createFromConnectionString(connectionString);

export abstract class ServiceBusTest<TOptions> extends PerfStressTest<TOptions> {
sbClient: ServiceBusClient;
static queueName = getEnvVar("QUEUE_NAME");

constructor() {
super();
this.sbClient = sbClient;
}

public async globalCleanup() {
await this.sbClient.close();
}
}
45 changes: 45 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/sendBatch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressOptionDictionary } from "@azure/test-utils-perfstress";
import { SendableMessageInfo, Sender } from "@azure/service-bus";
import { ServiceBusTest } from "./sbBase.spec";

interface SendTestOptions {
messageBodySize: number;
numberOfMessages: number;
}

export class BatchSendTest extends ServiceBusTest<SendTestOptions> {
sender: Sender;
batch: SendableMessageInfo[];
public options: PerfStressOptionDictionary<SendTestOptions> = {
messageBodySize: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
},
numberOfMessages: {
required: true,
description: "Number of messages per send",
shortName: "num",
longName: "numberOfMessages",
defaultValue: 10
}
};

constructor() {
super();
this.sender = this.sbClient.createQueueClient(BatchSendTest.queueName).createSender();
const sbMessage = {
body: Buffer.alloc(this.parsedOptions.messageBodySize.value!)
};
this.batch = new Array(this.parsedOptions.numberOfMessages.value!).fill(sbMessage);
}

async runAsync(): Promise<void> {
await this.sender.sendBatch(this.batch);
}
}
5 changes: 5 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
11 changes: 11 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Guide

1. Build the service-bus package `rush build -t service-bus`.
2. Navigate to `service-bus` folder `cd sdk\servicebus\service-bus\`.
3. Create a service-bus namespace and populate the .env file at `servicebus\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` variables.
4. Run the tests as follows

- simple send
- `npm run perf-test:node -- SimpleSendTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- batch send
- `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`
11 changes: 11 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-2/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
import { BatchSendTest } from "./sendBatch.spec";

console.log("=== Starting the perfStress test ===");

const perfStressProgram = new PerfStressProgram(selectPerfStressTest([BatchSendTest]));

perfStressProgram.run();
32 changes: 32 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-2/sbBase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest, getEnvVar } from "@azure/test-utils-perfstress";
import { ServiceBusAdministrationClient, ServiceBusClient } from "../../../src";

// Expects the .env file at the same level as the "test" folder
import * as dotenv from "dotenv";
dotenv.config();

const connectionString = getEnvVar("SERVICEBUS_CONNECTION_STRING");
const sbClient = new ServiceBusClient(connectionString);

export abstract class ServiceBusTest<TOptions> extends PerfStressTest<TOptions> {
sbClient: ServiceBusClient;
static sbAdminClient = new ServiceBusAdministrationClient(connectionString);
static queueName = `newqueue-${Math.ceil(Math.random() * 1000)}`;

constructor() {
super();
this.sbClient = sbClient;
}

public async globalSetup() {
await ServiceBusTest.sbAdminClient.createQueue(ServiceBusTest.queueName);
}

public async globalCleanup() {
await ServiceBusTest.sbAdminClient.deleteQueue(ServiceBusTest.queueName);
await this.sbClient.close();
}
}
45 changes: 45 additions & 0 deletions sdk/servicebus/service-bus/test/perf/track-2/sendBatch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressOptionDictionary } from "@azure/test-utils-perfstress";
import { ServiceBusMessage, ServiceBusSender } from "../../../src";
import { ServiceBusTest } from "./sbBase.spec";

interface SendTestOptions {
messageBodySize: number;
numberOfMessages: number;
}

export class BatchSendTest extends ServiceBusTest<SendTestOptions> {
sender: ServiceBusSender;
batch: ServiceBusMessage[];
public options: PerfStressOptionDictionary<SendTestOptions> = {
messageBodySize: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
},
numberOfMessages: {
required: true,
description: "Number of messages per send",
shortName: "num",
longName: "numberOfMessages",
defaultValue: 10
}
};

constructor() {
super();
this.sender = this.sbClient.createSender(BatchSendTest.queueName);
const sbMessage = {
body: Buffer.alloc(this.parsedOptions.messageBodySize.value!)
};
this.batch = new Array(this.parsedOptions.numberOfMessages.value!).fill(sbMessage);
}

async runAsync(): Promise<void> {
await this.sender.sendMessages(this.batch);
}
}
3 changes: 2 additions & 1 deletion sdk/servicebus/service-bus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"node_modules",
"./types/**/*.d.ts",
"./samples/**/*.ts",
"test/perf/*",
"test/perf-js-libs/*",
"test/perf/track-1",
"test/stress*"
],
"include": ["./src/**/*.ts", "./test/**/*.ts"]
Expand Down

0 comments on commit e15c042

Please sign in to comment.