Skip to content

Commit 8dcecef

Browse files
authored
[text analytics] add perf tests (#17060)
1 parent 303ff1f commit 8dcecef

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Text Analytics Performance Tests
2+
3+
In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the `dev_requirements` install.
4+
Start by creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7.
5+
6+
### Setup for test resources
7+
8+
The following environment variable will need to be set for the tests to access the live resources:
9+
10+
```
11+
AZURE_TEXT_ANALYTICS_ENDPOINT=<text analytics service endpoint>
12+
AZURE_TEXT_ANALYTICS_KEY=<text analytics API Key>
13+
```
14+
15+
### Setup for perf test runs
16+
17+
```cmd
18+
(env) ~/azure-ai-textanalytics> pip install -r dev_requirements.txt
19+
(env) ~/azure-ai-textanalytics> pip install -e .
20+
```
21+
22+
## Test commands
23+
24+
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).
25+
26+
```cmd
27+
(env) ~/azure-ai-textanalytics> cd tests/perfstress_tests/
28+
(env) ~/azure-ai-textanalytics/tests/perfstress_tests> perfstress
29+
```
30+
Using the `perfstress` command alone will list the available perf tests found.
31+
32+
### Common perf command line options
33+
These options are available for all perf tests:
34+
- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
35+
- `--iterations=1` Number of test iterations to run. Default is 1.
36+
- `--parallel=1` Number of tests to run in parallel. Default is 1.
37+
- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
38+
- `--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.
39+
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
40+
41+
## Example command
42+
```cmd
43+
(env) ~/azure-ai-textanalytics/tests/perfstress_tests> perfstress DetectLanguagePerfStressTest
44+
```

sdk/textanalytics/azure-ai-textanalytics/tests/perfstress_tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# coding=utf-8
2+
# ------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT License.
5+
# ------------------------------------
6+
import os
7+
from azure_devtools.perfstress_tests import PerfStressTest
8+
from azure.core.credentials import AzureKeyCredential
9+
from azure.ai.textanalytics import TextAnalyticsClient
10+
from azure.ai.textanalytics.aio import TextAnalyticsClient as AsyncTextAnalyticsClient
11+
12+
class DetectLanguagePerfStressTest(PerfStressTest):
13+
def __init__(self, arguments):
14+
super().__init__(arguments)
15+
16+
# test related env vars
17+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
18+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
19+
20+
# assign the clients that will be used in the perf tests
21+
self.service_client = TextAnalyticsClient(
22+
endpoint=endpoint,
23+
credential=AzureKeyCredential(key),
24+
)
25+
self.async_service_client = AsyncTextAnalyticsClient(
26+
endpoint=endpoint,
27+
credential=AzureKeyCredential(key),
28+
)
29+
30+
async def close(self):
31+
"""This is run after cleanup."""
32+
await self.async_service_client.close()
33+
self.service_client.close()
34+
await super().close()
35+
36+
def run_sync(self):
37+
"""The synchronous perf test."""
38+
self.service_client.detect_language(["This is in English"])
39+
40+
async def run_async(self):
41+
"""The asynchronous perf test."""
42+
await self.async_service_client.detect_language(["This is in English"])

0 commit comments

Comments
 (0)