From 3d74eb737884c5ab6838f9d5fadb3221952d306d Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 25 Feb 2021 12:15:05 -0800 Subject: [PATCH 1/4] initialize --- .../tests/perfstress_tests/README.md | 0 .../tests/perfstress_tests/__init__.py | 0 .../tests/perfstress_tests/send.py | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md create mode 100644 sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/__init__.py create mode 100644 sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/__init__.py b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py new file mode 100644 index 000000000000..c77634c54246 --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py @@ -0,0 +1,25 @@ +from azure_devtools.perfstress_tests import PerfStressTest + +from azure.eventgrid import EventGridPublisherClient as SyncPublisherClient, EventGridEvent +from azure.eventgrid.aio import EventGridPublisherClient as AsyncPublisherClient + +from azure.core.credentials import AzureKeyCredential + +class EventGridPerfTest(PerfStressTest): + def __init__(self, arguments): + super().__init__(arguments) + + # auth configuration + topic_key = self.get_from_env("EG_ACCESS_KEY") + endpoint = self.get_from_env("EG_TOPIC_HOSTNAME") + + # Create clients + self.publisher_client = SyncPublisherClient( + endpoint=endpoint + credential=AzureKeyCredential(topic_key) + ) + self._async_publisher_client = AsyncPublisherClient( + endpoint=endpoint, + credential=AzureKeyCredential(topic_key) + ) + \ No newline at end of file From aa26196705e130b9b528184f1dd22c320504f9ae Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 25 Feb 2021 14:11:12 -0800 Subject: [PATCH 2/4] implementation --- .../tests/perfstress_tests/README.md | 49 ++++++++++++++++++ .../tests/perfstress_tests/send.py | 50 +++++++++++++++++-- 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md index e69de29bb2d1..f41d04b468c0 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md @@ -0,0 +1,49 @@ +# EventGrid Performance Tests + +In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the `dev_requirements`. +Start by creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7. + +### Setup for test resources + +These tests will run against a pre-configured Eventgrid topic. The following environment variable will need to be set for the tests to access the live resources: +``` +EG_ACCESS_KEY= +EG_TOPIC_HOSTNAME= +``` + +### Setup for perf test runs + +```cmd +(env) ~/azure-eventgrid> pip install -r dev_requirements.txt +(env) ~/azure-eventgrid> pip install -e . +``` + +## Test commands + +```cmd +(env) ~/azure-eventgrid> cd tests +(env) ~/azure-eventgrid/tests> perfstress +``` + +### Common perf command line options +These options are available for all perf tests: +- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10. +- `--iterations=1` Number of test iterations to run. Default is 1. +- `--parallel=1` Number of tests to run in parallel. Default is 1. +- `--no-client-share` Whether each parallel test instance should share a single client, or use their own. Default is False (sharing). +- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. +- `--sync` Whether to run the tests in sync or async. Default is False (async). This flag must be used for Storage legacy tests, which do not support async. +- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted). + +### EventGrid Test options +These options are available for all eventgrid perf tests: +- `--num-events` Number of events to be published using the send method. + +### T2 Tests +The tests currently written for the T2 SDK: +- `EventGridPerfTest` Publishes a list of eventgrid events. + +## Example command +```cmd +(env) ~/azure-eventgrid/tests> perfstress EventGridPerfTest --num-events=100 +``` diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py index c77634c54246..4f2749f57c46 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py @@ -1,3 +1,5 @@ +import random +import asyncio from azure_devtools.perfstress_tests import PerfStressTest from azure.eventgrid import EventGridPublisherClient as SyncPublisherClient, EventGridEvent @@ -15,11 +17,53 @@ def __init__(self, arguments): # Create clients self.publisher_client = SyncPublisherClient( - endpoint=endpoint + endpoint=endpoint, credential=AzureKeyCredential(topic_key) ) - self._async_publisher_client = AsyncPublisherClient( + self.async_publisher_client = AsyncPublisherClient( endpoint=endpoint, credential=AzureKeyCredential(topic_key) ) - \ No newline at end of file + + services = ["EventGrid", "ServiceBus", "EventHubs", "Storage"] + self.event_list = [] + for _ in range(self.args.num_events): + self.event_list.append(EventGridEvent( + event_type="Contoso.Items.ItemReceived", + data={ + "services": random.sample(services, k=random.randint(1, 4)) + }, + subject="Door1", + data_version="2.0" + )) + + async def close(self): + """This is run after cleanup. + + Use this to close any open handles or clients. + """ + await self.async_publisher_client.close() + await super().close() + + def run_sync(self): + """The synchronous perf test. + + Try to keep this minimal and focused. Using only a single client API. + Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead + so that we're only measuring the client API call. + """ + self.publisher_client.send(self.event_list) + + async def run_async(self): + """The asynchronous perf test. + + Try to keep this minimal and focused. Using only a single client API. + Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead + so that we're only measuring the client API call. + """ + await self.async_publisher_client.send(self.event_list) + + @staticmethod + def add_arguments(parser): + super(EventGridPerfTest, EventGridPerfTest).add_arguments(parser) + parser.add_argument('-n', '--num-events', nargs='?', type=int, help='Number of events to be sent. Defaults to 100', default=100) From 594ec26c715a1acd40ffec0fc3dd320b06189f11 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 25 Feb 2021 14:33:44 -0800 Subject: [PATCH 3/4] Update sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md --- sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md index f41d04b468c0..245a8efb462f 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md @@ -32,7 +32,7 @@ These options are available for all perf tests: - `--parallel=1` Number of tests to run in parallel. Default is 1. - `--no-client-share` Whether each parallel test instance should share a single client, or use their own. Default is False (sharing). - `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. -- `--sync` Whether to run the tests in sync or async. Default is False (async). This flag must be used for Storage legacy tests, which do not support async. +- `--sync` Whether to run the tests in sync or async. Default is False (async). - `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted). ### EventGrid Test options From 6a0fd6ac88eceb9b9ec692be7eb6ed0039b3cd8c Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 25 Feb 2021 16:23:12 -0800 Subject: [PATCH 4/4] comments --- .../azure-eventgrid/tests/perfstress_tests/README.md | 1 - .../azure-eventgrid/tests/perfstress_tests/send.py | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md index 245a8efb462f..7e51435d647f 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/README.md @@ -30,7 +30,6 @@ These options are available for all perf tests: - `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10. - `--iterations=1` Number of test iterations to run. Default is 1. - `--parallel=1` Number of tests to run in parallel. Default is 1. -- `--no-client-share` Whether each parallel test instance should share a single client, or use their own. Default is False (sharing). - `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. - `--sync` Whether to run the tests in sync or async. Default is False (async). - `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted). diff --git a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py index 4f2749f57c46..4f13b3c39cfe 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py +++ b/sdk/eventgrid/azure-eventgrid/tests/perfstress_tests/send.py @@ -1,4 +1,9 @@ -import random +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + import asyncio from azure_devtools.perfstress_tests import PerfStressTest @@ -25,13 +30,12 @@ def __init__(self, arguments): credential=AzureKeyCredential(topic_key) ) - services = ["EventGrid", "ServiceBus", "EventHubs", "Storage"] self.event_list = [] for _ in range(self.args.num_events): self.event_list.append(EventGridEvent( event_type="Contoso.Items.ItemReceived", data={ - "services": random.sample(services, k=random.randint(1, 4)) + "services": ["EventGrid", "ServiceBus", "EventHubs", "Storage"] }, subject="Door1", data_version="2.0"