Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] Perf tests with the framework #12993

Merged
22 commits merged into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future concern: should we be using .tryAdd() ourselves or are we guaranteed that we'll never exceed the size of a single batch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, makes sense to use tryAdd. I'll put a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
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/*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I get what goes in perf-js-libs vs perf/track-? Is it just archiving these files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More or less, yes.

perf-js-libs

  • perf-js-libs/azure-sb-package
  • perf-js-libs/rhea-promise
  • perf-js-libs/service-bus-v1
  • perf-js-libs/service-bus-v7

perf/track-*

  • perf/track-1 - v1
  • perf/track-2 - v7

Description

  • perf-js-libs do not use the framework and have the tests for send, streaming receive and batch receive.
  • perf/track-* uses the framework for send test, and currently has the send test only.
    • Since this uses the framework, it helps with comparisons across languages.
  • Framework isn't capable of handling the receive tests, so they have to be standalone tests.

More thoughts

  • Eventually, I intend to have the standalone tests in the perf/track-* folder itself and thus removing the need for perf-js-libs/service-bus-v* folders.
  • The perf-js-libs/azure-sb-package can be removed as it is pretty much outdated at the moment.
  • That leaves us with perf-js-libs/rhea-promise, which could be moved to perf/rhea-promise after updating the send test with the framework and migrating the standalone receive tests.
  • Finally, we'll end up with perf/track-1, perf/track-2 and perf/rhea-promise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test/perf/track-1",
"test/stress*"
],
"include": ["./src/**/*.ts", "./test/**/*.ts"]
Expand Down