-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Perf tests/service-bus-track-1] Add batch receive perf tests for Ser…
…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
Showing
7 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
sdk/servicebus/perf-tests/service-bus-track-1/test/receiveBatch.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters