forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[text analytics] add perf tests (Azure#17060)
- Loading branch information
1 parent
303ff1f
commit 8dcecef
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/README.md
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,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: | ||
|
||
``` | ||
AZURE_TEXT_ANALYTICS_ENDPOINT=<text analytics service endpoint> | ||
AZURE_TEXT_ANALYTICS_KEY=<text analytics 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 | ||
``` |
Empty file.
42 changes: 42 additions & 0 deletions
42
sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/perf_detect_language.py
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,42 @@ | ||
# 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 | ||
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"]) |