From 569c2167c98e0cea29673b01c17fd292f30b7a0e Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 3 Mar 2021 11:31:04 -0500 Subject: [PATCH 1/3] temp --- .../tests/perfstress_tests/README.md | 44 +++++++++++++++++++ .../perfstress_tests/perf_detect_language.py | 20 +++++++++ 2 files changed, 64 insertions(+) create mode 100644 sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md create mode 100644 sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md new file mode 100644 index 000000000000..b8f18a429f3a --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md @@ -0,0 +1,44 @@ +# Text Analytics 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` install. +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 + +The following environment variable will need to be set for the tests to access the live resources: + +``` +TEXTANALYTICS_TEST_ENDPOINT= +TEXTANALYTICS_TEST_API_KEY= +``` + +### Setup for perf test runs + +```cmd +(env) ~/azure-ai-textanalytics> pip install -r dev_requirements.txt +(env) ~/azure-ai-textanalytics> pip install -e . +``` + +## Test commands + +When `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the current module for runable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature). + +```cmd +(env) ~/azure-ai-textanalytics> cd tests/perfstress_tests/ +(env) ~/azure-ai-textanalytics/tests/perfstress_tests> perfstress +``` +Using the `perfstress` command alone will list the available perf tests found. + +### 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. +- `--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). + +## Example command +```cmd +(env) ~/azure-ai-textanalytics/tests/perfstress_tests> perfstress DetectLanguagePerfStressTest +``` \ No newline at end of file diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py new file mode 100644 index 000000000000..22b92b61c11c --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py @@ -0,0 +1,20 @@ +# coding=utf-8 +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +import os +from azure_devtools.perfstress_tests import PerfStressTest +from azure.core.credentials import AzureKeyCredential +from azure.ai.textanalytics import TextAnalyticsClient +from azure.ai.textanalytics.aio import TextAnalyticsClient as AsyncTextAnalyticsClient + +class DetectLanguagePerfStressTest(PerfStressTest): + def __init__(self, arguments): + super().__init__(arguments) + + # test related env vars + self.textanalytics_test_endpoint = os.environ["TEXTANALYTICS_TEST_ENDPOINT"] + self.textanalytics_test_api_key = os.environ["TEXTANALYTICS_TEST_API_KEY"] + + # assign the clients that will be used in the perf tests From 98a035649bd9aa5e8f9401d66392f43a6382408c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 3 Mar 2021 11:52:54 -0500 Subject: [PATCH 2/3] add perf tests with detect language --- .../tests/perfstress_tests/README.md | 4 +-- .../perfstress_tests/perf_detect_language.py | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md index b8f18a429f3a..e50a4e4deb80 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md @@ -8,8 +8,8 @@ Start by creating a new virtual environment for your perf tests. This will need The following environment variable will need to be set for the tests to access the live resources: ``` -TEXTANALYTICS_TEST_ENDPOINT= -TEXTANALYTICS_TEST_API_KEY= +AZURE_TEXT_ANALYTICS_ENDPOINT= +AZURE_TEXT_ANALYTICS_KEY= ``` ### Setup for perf test runs diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py index 22b92b61c11c..15d2dc17dc06 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py @@ -14,7 +14,29 @@ def __init__(self, arguments): super().__init__(arguments) # test related env vars - self.textanalytics_test_endpoint = os.environ["TEXTANALYTICS_TEST_ENDPOINT"] - self.textanalytics_test_api_key = os.environ["TEXTANALYTICS_TEST_API_KEY"] + endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"] + key = os.environ["AZURE_TEXT_ANALYTICS_KEY"] # assign the clients that will be used in the perf tests + self.service_client = TextAnalyticsClient( + endpoint=endpoint, + credential=AzureKeyCredential(key), + ) + self.async_service_client = AsyncTextAnalyticsClient( + endpoint=endpoint, + credential=AzureKeyCredential(key), + ) + + async def close(self): + """This is run after cleanup.""" + await self.async_service_client.close() + self.service_client.close() + await super().close() + + def run_sync(self): + """The synchronous perf test.""" + self.service_client.detect_language(["This is in English"]) + + async def run_async(self): + """The asynchronous perf test.""" + await self.async_service_client.detect_language(["This is in English"]) From 4914feb809f2e725748929fe24eafe7fba5d4928 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 3 Mar 2021 13:18:15 -0500 Subject: [PATCH 3/3] add empty init file --- .../azure-ai-textanalytics/tests/perfstress_tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/__init__.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/__init__.py b/sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1