Skip to content

Commit 1923e0d

Browse files
authored
[Perf] corehttp - updating async stream upload httpx test (#34674)
* add async iterator random stream for async httpx * update perf tests with same args for easier comparison of perf * pauls comments * update asynciterator comment to iterable
1 parent 83a137e commit 1923e0d

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

sdk/core/azure-core/perf-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Tests:
1414
Arguments:
1515
- --size 1024 --parallel 64 --duration 60 --policies all
1616
- --size 1024 --parallel 64 --duration 60 --policies all --use-entra-id
17-
- --size 10240 --parallel 32 --duration 60
18-
- --size 10240 --parallel 32 --duration 60 --transport requests
17+
- --size 10240 --parallel 64 --duration 60
18+
- --size 10240 --parallel 64 --duration 60 --transport requests
1919

2020
- Test: download-binary
2121
Class: DownloadBinaryDataTest
2222
Arguments:
2323
- --size 1024 --parallel 64 --duration 60
2424
- --size 1024 --parallel 64 --duration 60 --transport requests
2525
- --size 1024 --parallel 64 --duration 60 --use-entra-id
26-
- --size 10240 --parallel 32 --duration 60 --policies all
26+
- --size 10240 --parallel 64 --duration 60 --policies all
2727

2828
- Test: update-entity
2929
Class: UpdateEntityJSONTest

sdk/core/corehttp/perf-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Tests:
1414
Arguments:
1515
- --size 1024 --parallel 64 --duration 60 --policies all
1616
- --size 1024 --parallel 64 --duration 60 --policies all --use-entra-id
17-
- --size 10240 --parallel 32 --duration 60
18-
- --size 10240 --parallel 32 --duration 60 --transport httpx
17+
- --size 10240 --parallel 64 --duration 60
18+
- --size 10240 --parallel 64 --duration 60 --transport httpx
1919

2020
- Test: download-binary
2121
Class: DownloadBinaryDataTest
2222
Arguments:
2323
- --size 1024 --parallel 64 --duration 60
2424
- --size 1024 --parallel 64 --duration 60 --transport httpx
2525
- --size 1024 --parallel 64 --duration 60 --use-entra-id
26-
- --size 10240 --parallel 32 --duration 60 --policies all
26+
- --size 10240 --parallel 64 --duration 60 --policies all
2727

2828
- Test: update-entity
2929
Class: UpdateEntityJSONTest

sdk/core/corehttp/tests/perf_tests/upload_binary.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from time import time
77
from wsgiref.handlers import format_date_time
8-
from devtools_testutils.perfstress_tests import RandomStream, AsyncRandomStream
8+
from devtools_testutils.perfstress_tests import RandomStream, AsyncRandomStream, AsyncIteratorRandomStream
99

1010
from corehttp.rest import HttpRequest
1111
from corehttp.exceptions import (
@@ -29,7 +29,14 @@ def __init__(self, arguments):
2929
blob_name = "uploadtest"
3030
self.blob_endpoint = f"{self.account_endpoint}{self.container_name}/{blob_name}"
3131
self.upload_stream = RandomStream(self.args.size)
32-
self.upload_stream_async = AsyncRandomStream(self.args.size)
32+
33+
# The AsyncIteratorRandomStream is used for upload stream scenario, since the
34+
# async httpx transport requires the request body stream to be type AsyncIterable (i.e. have an __aiter__ method rather than __iter__).
35+
# Specific check in httpx here: https://github.com/encode/httpx/blob/7df47ce4d93a06f2c3310cd692b4c2336d7663ba/httpx/_content.py#L116.
36+
if self.args.transport == "httpx":
37+
self.upload_stream_async = AsyncIteratorRandomStream(self.args.size)
38+
else:
39+
self.upload_stream_async = AsyncRandomStream(self.args.size)
3340

3441
def run_sync(self):
3542
self.upload_stream.reset()

tools/azure-sdk-tools/devtools_testutils/perfstress_tests/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ._perf_stress_runner import _PerfStressRunner
1010
from ._perf_stress_test import PerfStressTest
1111
from ._random_stream import RandomStream, WriteStream, get_random_bytes
12-
from ._async_random_stream import AsyncRandomStream
12+
from ._async_random_stream import AsyncRandomStream, AsyncIteratorRandomStream
1313
from ._batch_perf_test import BatchPerfTest
1414
from ._event_perf_test import EventPerfTest
1515

@@ -19,6 +19,7 @@
1919
"EventPerfTest",
2020
"RandomStream",
2121
"WriteStream",
22+
"AsyncIteratorRandomStream",
2223
"AsyncRandomStream",
2324
"get_random_bytes"
2425
]

tools/azure-sdk-tools/devtools_testutils/perfstress_tests/_async_random_stream.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6+
from typing import AsyncIterator
67
from io import BytesIO
78

89
from ._random_stream import get_random_bytes, _DEFAULT_LENGTH
@@ -58,3 +59,46 @@ def remaining(self):
5859

5960
def close(self):
6061
self._closed = True
62+
63+
64+
class AsyncIteratorRandomStream(AsyncIterator[bytes]):
65+
"""
66+
Async random stream of bytes for methods that accept AsyncIterator as input.
67+
"""
68+
def __init__(self, length, initial_buffer_length=_DEFAULT_LENGTH):
69+
self._base_data = get_random_bytes(initial_buffer_length)
70+
self._data_length = length
71+
self._base_buffer_length = initial_buffer_length
72+
self._position = 0
73+
self._remaining = length
74+
75+
def __len__(self):
76+
return self._remaining
77+
78+
def __aiter__(self):
79+
return self
80+
81+
async def __anext__(self):
82+
if self._remaining == 0:
83+
raise StopAsyncIteration
84+
return self.read()
85+
86+
def reset(self):
87+
self._position = 0
88+
self._remaining = self._data_length
89+
90+
def read(self, size=None):
91+
if self._remaining == 0:
92+
return b""
93+
94+
if size is None:
95+
e = self._base_buffer_length
96+
else:
97+
e = size
98+
e = min(e, self._remaining)
99+
if e > self._base_buffer_length:
100+
self._base_data = get_random_bytes(e)
101+
self._base_buffer_length = e
102+
self._remaining = self._remaining - e
103+
self._position += e
104+
return self._base_data[:e]

0 commit comments

Comments
 (0)