Skip to content

Commit

Permalink
[Perf tests/service-bus-track-1] Add batch receive perf tests for Ser…
Browse files Browse the repository at this point in the history
…vice Bus Track 1 (#19790)

**Packages impacted by this PR:**

- `@azure-tests/perf-service-bus-track-1`

**Issues associated with this PR:**

- #18982

**Describe the problem that is addressed by this PR:**

Add a test for receiveBatch using the track 1 service bus SDK in line with what we already have for the track 2 SDK

**Provide a list of related PRs** _(if any)_
- #18811
  • Loading branch information
timovv committed Jan 20, 2022
1 parent 93ee7db commit 99f2b37
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 11 deletions.
10 changes: 8 additions & 2 deletions sdk/servicebus/perf-tests/service-bus-track-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ Create a service-bus namespace and populate the .env file with `SERVICEBUS_CONNE

## Running the tests

To test sending messages in batches
To test sending messages in batches:

> `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`
> `npm run perf-test:node -- BatchSendTest --warmup 1 --duration 25 --iterations 2 --parallel 32 --messageBodySize 10240 --numberOfMessages 10`
To test receiving messages in batches:

> `npm run perf-test:node -- BatchReceiveTest --warmup 1 --duration 25 --iterations 2 --parallel 32 --size-in-bytes 2000 --number-of-messages 50`
To test `receiveMessages` - receiving messages in batches

> `npm run perf-test:node -- BatchReceiveTest --duration 5 --size 2000`
_Note: For more default options, refer [Perf-Framework-Default-Options](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/test-utils/perf/README.md#keyconcepts)._
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Licensed under the MIT license.

import { PerfProgram, selectPerfTest } from "@azure/test-utils-perf";
import { BatchReceiveTest } from "./receiveBatch.spec";
import { BatchSendTest } from "./sendBatch.spec";

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

const perfProgram = new PerfProgram(selectPerfTest([BatchSendTest]));
const perfProgram = new PerfProgram(selectPerfTest([BatchSendTest, BatchReceiveTest]));

perfProgram.run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ReceiveMode, Receiver, Sender } from "@azure/service-bus";
import { PerfOptionDictionary } from "@azure/test-utils-perf";
import { ServiceBusTest } from "./sbBase.spec";

interface ReceiverOptions {
"max-message-count": number;
"number-of-messages": number;
"message-body-size-in-bytes": number;
}

/**
* An underestimate of the true maximum size of a batch send message in bytes.
* This number is used to split up the send requests into small enough chunks
* to be accepted.
*/
const MAX_SEND_BATCH_SIZE_BYTES = 200000;

export class BatchReceiveTest extends ServiceBusTest<ReceiverOptions> {
receiver: Receiver;
public options: PerfOptionDictionary<ReceiverOptions> = {
"number-of-messages": {
required: true,
description: "Total number of messages to send",
shortName: "send",
defaultValue: 10000,
},
"message-body-size-in-bytes": {
required: true,
description: "Size of each message body in bytes",
shortName: "size",
defaultValue: 2000,
},
"max-message-count": {
required: true,
description: "Max number of messages to receive",
shortName: "max-receive",
defaultValue: 50,
},
};

constructor() {
super();
this.receiver = ServiceBusTest.sbClient
.createQueueClient(BatchReceiveTest.queueName)
.createReceiver(ReceiveMode.receiveAndDelete);
}

/**
* Sends the messages to be received later.
*/
public async globalSetup(): Promise<void> {
await super.globalSetup();
const sender = ServiceBusTest.sbClient
.createQueueClient(BatchReceiveTest.queueName)
.createSender();

const {
"number-of-messages": { value: numberOfMessages },
"message-body-size-in-bytes": { value: messageBodySize },
} = this.parsedOptions;

await sendMessages(sender, numberOfMessages, messageBodySize);
}

public async runBatch(): Promise<number> {
const messages = await this.receiver.receiveMessages(
this.parsedOptions["max-message-count"].value,
0.5
);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const _ in messages) {
// This is to represent the bare minimum user scenario where one would
// iterate over the messages and process them
}
return messages.length;
}
}

async function sendMessages(sender: Sender, numberOfMessages: number, messageBodySize: number) {
let messagesSent = 0;

while (messagesSent < numberOfMessages) {
let messagesThisBatch = Math.min(
numberOfMessages - messagesSent,
Math.floor(MAX_SEND_BATCH_SIZE_BYTES / messageBodySize)
);
await sender.sendBatch(Array(messagesThisBatch).fill({ body: Buffer.alloc(messageBodySize) }));
messagesSent += messagesThisBatch;
console.log(`${messagesSent} messages sent so far`);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfTest, getEnvVar } from "@azure/test-utils-perf";
import { getEnvVar, BatchPerfTest } from "@azure/test-utils-perf";
import { ServiceBusClient } from "@azure/service-bus";
import { ServiceBusAdministrationClient } from "@azure/service-bus-v7";

Expand All @@ -11,7 +11,7 @@ dotenv.config();

const connectionString = getEnvVar("SERVICEBUS_CONNECTION_STRING");

export abstract class ServiceBusTest<TOptions> extends PerfTest<TOptions> {
export abstract class ServiceBusTest<TOptions> extends BatchPerfTest<TOptions> {
static sbClient: ServiceBusClient = ServiceBusClient.createFromConnectionString(connectionString);
static sbAdminClient = new ServiceBusAdministrationClient(connectionString);
static queueName = `newqueue-${Math.ceil(Math.random() * 1000)}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class BatchSendTest extends ServiceBusTest<SendTestOptions> {
this.batch = new Array(this.parsedOptions.numberOfMessages.value!).fill(sbMessage);
}

async run(): Promise<void> {
async runBatch(): Promise<number> {
await BatchSendTest.sender.sendBatch(this.batch);
return this.batch.length;
}
}
2 changes: 1 addition & 1 deletion sdk/servicebus/perf-tests/service-bus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ To test sending messages in batches
To test `receiveMessages` - receiving messages in batches

> `npm run perf-test:node -- BatchReceiveTest --duration 5 --size 2000`
> `npm run perf-test:node -- BatchReceiveTest --duration 5 --size 2000 --number-of-messages 10000 --size-in-bytes 2000 --max-message-count 50`
_Note: For more default options, refer [Perf-Framework-Default-Options](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/test-utils/perf/README.md#keyconcepts)._
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export class BatchReceiveTest extends ServiceBusTest<ReceiverOptions> {
"number-of-messages": {
required: true,
description: "Total number of messages to send",
shortName: "max",
longName: "maximum",
shortName: "send",
defaultValue: 10000,
},
"message-body-size-in-bytes": {
Expand All @@ -31,8 +30,7 @@ export class BatchReceiveTest extends ServiceBusTest<ReceiverOptions> {
"max-message-count": {
required: true,
description: "Max number of messages to receive",
shortName: "max",
longName: "maximum",
shortName: "max-receive",
defaultValue: 50,
},
};
Expand Down

0 comments on commit 99f2b37

Please sign in to comment.