-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Perf] Call Run() once before starting recording (#21162)
- Avoids capturing one-time setup like authorization requests - Ported from Azure/azure-sdk-for-net#24263
- Loading branch information
1 parent
fbdf6f4
commit af4869b
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
...evtools/src/azure_devtools/perfstress_tests/system_perfstress/pipeline_client_get_test.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,60 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.core import PipelineClient | ||
from azure.core import AsyncPipelineClient | ||
from azure.core.pipeline import PipelineResponse | ||
from azure.core.pipeline.transport import HttpResponse | ||
|
||
from azure_devtools.perfstress_tests import PerfStressTest | ||
|
||
|
||
class PipelineClientGetTest(PerfStressTest): | ||
pipeline_client: PipelineClient = None | ||
async_pipeline_client: AsyncPipelineClient = None | ||
_first_run = True | ||
|
||
def __init__(self, arguments): | ||
super().__init__(arguments) | ||
self.pipeline_client = PipelineClient(base_url=self.args.url, **self._client_kwargs) | ||
self.async_pipeline_client = AsyncPipelineClient(base_url=self.args.url, **self._client_kwargs) | ||
|
||
def run_sync(self): | ||
if self._first_run: | ||
for _ in range(self.args.first_run_extra_requests): | ||
self._send_request_sync() | ||
self._first_run = False | ||
self._send_request_sync() | ||
|
||
async def run_async(self): | ||
if self._first_run: | ||
for _ in range(self.args.first_run_extra_requests): | ||
await self._send_request_async() | ||
self._first_run = False | ||
await self._send_request_async() | ||
|
||
def _send_request_sync(self): | ||
request = self.pipeline_client.get(self.args.url) | ||
response: PipelineResponse = self.pipeline_client._pipeline.run(request) | ||
# Consume response body | ||
http_response: HttpResponse = response.http_response | ||
data = http_response.body() | ||
|
||
async def _send_request_async(self): | ||
request = self.async_pipeline_client.get(self.args.url) | ||
response: PipelineResponse = await self.async_pipeline_client._pipeline.run(request) | ||
# Consume response body | ||
http_response: HttpResponse = response.http_response | ||
data = http_response.body() | ||
|
||
async def close(self): | ||
await self.async_pipeline_client.close() | ||
await super().close() | ||
|
||
@staticmethod | ||
def add_arguments(parser): | ||
parser.add_argument("--first-run-extra-requests", type=int, default=0, help='Extra requests to send on first run. ' + | ||
'Simulates SDKs which require extra requests (like authentication) on first API call.') | ||
parser.add_argument("-u", "--url", required=True) |