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.
[formrecognizer] Add perf tests for DAC client (Azure#22163)
* add perf tests for request prep and initial service call * add DMAC perf test
- Loading branch information
1 parent
7103a16
commit e70de26
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...e-ai-formrecognizer/tests/perfstress_tests/perf_dac_analyze_document_from_url_requests.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,46 @@ | ||
# 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.formrecognizer import DocumentAnalysisClient | ||
from azure.ai.formrecognizer.aio import DocumentAnalysisClient as AsyncDocumentAnalysisClient | ||
|
||
class AnalyzeDocumentFromUrlRequestPreparation(PerfStressTest): | ||
|
||
def __init__(self, arguments): | ||
super().__init__(arguments) | ||
|
||
self.document_jpg_url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/forms/Form_1.jpg" | ||
|
||
# read test related env vars | ||
formrecognizer_test_endpoint = os.environ["FORMRECOGNIZER_TEST_ENDPOINT"] | ||
form_recognizer_account_key = os.environ["FORMRECOGNIZER_TEST_API_KEY"] | ||
|
||
# assign the clients that will be used in the perf tests | ||
self.service_client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
self.async_service_client = AsyncDocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_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.""" | ||
poller = self.service_client.begin_analyze_document_from_url( | ||
"prebuilt-document", | ||
self.document_jpg_url) | ||
assert poller | ||
|
||
async def run_async(self): | ||
"""The asynchronous perf test.""" | ||
poller = await self.async_service_client.begin_analyze_document_from_url( | ||
"prebuilt-document", | ||
self.document_jpg_url) | ||
assert poller |
47 changes: 47 additions & 0 deletions
47
...izer/azure-ai-formrecognizer/tests/perfstress_tests/perf_dac_analyze_document_requests.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,47 @@ | ||
# 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.formrecognizer import DocumentAnalysisClient | ||
from azure.ai.formrecognizer.aio import DocumentAnalysisClient as AsyncDocumentAnalysisClient | ||
|
||
class AnalyzeDocumentRequestPreparation(PerfStressTest): | ||
|
||
def __init__(self, arguments): | ||
super().__init__(arguments) | ||
|
||
with open(os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "./../sample_forms/forms/Form_1.jpg")), "rb") as fd: | ||
self.document_jpg = fd.read() | ||
|
||
# read test related env vars | ||
formrecognizer_test_endpoint = os.environ["FORMRECOGNIZER_TEST_ENDPOINT"] | ||
form_recognizer_account_key = os.environ["FORMRECOGNIZER_TEST_API_KEY"] | ||
|
||
# assign the clients that will be used in the perf tests | ||
self.service_client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
self.async_service_client = AsyncDocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_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.""" | ||
poller = self.service_client.begin_analyze_document( | ||
"prebuilt-document", | ||
self.document_jpg) | ||
assert poller | ||
|
||
async def run_async(self): | ||
"""The asynchronous perf test.""" | ||
poller = await self.async_service_client.begin_analyze_document( | ||
"prebuilt-document", | ||
self.document_jpg) | ||
assert poller |
41 changes: 41 additions & 0 deletions
41
...cognizer/azure-ai-formrecognizer/tests/perfstress_tests/perf_dmac_build_model_requests.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,41 @@ | ||
# 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.formrecognizer import DocumentModelAdministrationClient | ||
from azure.ai.formrecognizer.aio import DocumentModelAdministrationClient as AsyncDocumentModelAdministrationClient | ||
|
||
class BuildModelRequestPreparation(PerfStressTest): | ||
|
||
def __init__(self, arguments): | ||
super().__init__(arguments) | ||
|
||
# read test related env vars | ||
self.formrecognizer_storage_container_sas_url = os.environ["FORMRECOGNIZER_TRAINING_DATA_CONTAINER_SAS_URL"] | ||
formrecognizer_test_endpoint = os.environ["FORMRECOGNIZER_TEST_ENDPOINT"] | ||
form_recognizer_account_key = os.environ["FORMRECOGNIZER_TEST_API_KEY"] | ||
|
||
# assign the clients that will be used in the perf tests | ||
self.admin_client = DocumentModelAdministrationClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
self.async_admin_client = AsyncDocumentModelAdministrationClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
|
||
async def close(self): | ||
"""This is run after cleanup.""" | ||
await self.async_admin_client.close() | ||
self.admin_client.close() | ||
await super().close() | ||
|
||
def run_sync(self): | ||
"""The synchronous perf test.""" | ||
poller = self.admin_client.begin_build_model(self.formrecognizer_storage_container_sas_url) | ||
assert poller | ||
|
||
async def run_async(self): | ||
"""The asynchronous perf test.""" | ||
poller = await self.async_admin_client.begin_build_model(self.formrecognizer_storage_container_sas_url) | ||
assert poller |