|
| 1 | +# Core Python client performance tests |
| 2 | + |
| 3 | +In order to run the performance tests, the `devtools_testutils` package must be installed. This is done as part of the `dev_requirements.txt` installation. Start be creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7. |
| 4 | + |
| 5 | +### Setup for test resources |
| 6 | +The following environment variables will need to be set for the tests to access the live resources: |
| 7 | + |
| 8 | +``` |
| 9 | +AZURE_STORAGE_CONN_STR=<the connection string to the Storage account> |
| 10 | +AZURE_STORAGE_ACCOUNT_NAME=<the Storage account name> |
| 11 | +AZURE_STORAGE_ACCOUNT_KEY=<the Storage account key> |
| 12 | +
|
| 13 | +AZURE_STORAGE_CONTAINER_NAME=<the container name> |
| 14 | +AZURE_STORAGE_BLOBS_ENDPOINT=<The Storage Blobs endpoint in the format 'https://{storageAccountName}.blob.core.windows.net'> |
| 15 | +
|
| 16 | +AZURE_STORAGE_TABLE_NAME=<The name to use for the Storage Table> |
| 17 | +AZURE_STORAGE_TABLES_ENDPOINT=<The Storage Tables endpoint in the format 'https://{storageAccountName}.table.core.windows.net'> |
| 18 | +``` |
| 19 | + |
| 20 | +### Setup for perf test runs |
| 21 | + |
| 22 | +```cmd |
| 23 | +(env) ~/core/corehttp> pip install -r dev_requirements.txt |
| 24 | +(env) ~/core/corehttp> pip install . |
| 25 | +``` |
| 26 | + |
| 27 | +## Test commands |
| 28 | + |
| 29 | +When `devtools_testutils` 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). |
| 30 | + |
| 31 | +```cmd |
| 32 | +(env) ~/core/corehttp> cd tests |
| 33 | +(env) ~/core/corehttp/tests> perfstress |
| 34 | +``` |
| 35 | + |
| 36 | +Using the `perfstress` command alone will list the available perf tests found. |
| 37 | + |
| 38 | +### Tests |
| 39 | + |
| 40 | +The tests currently available: |
| 41 | + |
| 42 | +- `UploadBinaryDataTest` - Puts binary data of `size` in a Storage Blob (corresponds to the `upload_blob` Blob operation). |
| 43 | +- `DownloadBinaryDataTest` - Gets binary data of `size` from a Storage Blob (corresponds to the `download_blob` Blob operation). |
| 44 | +- `UpdateEntityJSONTest` - Puts JSON data of `size` in a Storage Table (corresponds to the `update_entity` Tables operation). |
| 45 | +- `QueryEntitiesJSONTest` - Gets JSON data of `size` from a Storage Table (corresponds to the `query_entities` Tables operation). |
| 46 | +- `ListEntitiesPageableTest` - Gets pageable data from a Storage Table (corresponds to the `list_entities` Tables operation). |
| 47 | + |
| 48 | +### Common perf command line options |
| 49 | + |
| 50 | +The `perfstress` framework has a series of common command line options built in. View them [here](https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/perfstress_tests.md#default-command-options). |
| 51 | + |
| 52 | +- `--sync` Whether to run the tests in sync or async. Default is False (async). |
| 53 | +- `-d --duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10. |
| 54 | +- `-i --iterations=1` Number of test iterations to run. Default is 1. |
| 55 | +- `-p --parallel=1` Number of tests to run in parallel. Default is 1. |
| 56 | +- `-w --warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. |
| 57 | + |
| 58 | +#### Core perf test common command line options |
| 59 | + |
| 60 | +The options that are available for all Core perf tests: |
| 61 | + |
| 62 | +- `--transport` - By default, uses AiohttpTransport ("aiohttp") for async. By default, uses RequestsTransport ("requests") for sync. All options: |
| 63 | + - For async: |
| 64 | + - `"aiohttp"`: AiohttpTransport (default) |
| 65 | + - `"httpx"`: AsyncHttpXTransport |
| 66 | + - For sync: |
| 67 | + - `"requests"`: RequestsTransport (default) |
| 68 | + - `"httpx"`: HttpXTransport |
| 69 | +- `--use-entra-id` - Flag to pass in to use Microsoft Entra ID as the authentication. By default, set to False. |
| 70 | +- `--size=10240` - Size of request content (in bytes). Defaults to 10240. (Not used by `ListEntitiesPageableTest`.) |
| 71 | +- `--policies` - List of policies to pass in to the pipeline. Options: |
| 72 | + - None: No extra policies passed in, except for authentication policy. This is the default. |
| 73 | + - 'all': All policies added automatically by autorest. |
| 74 | + - 'policy1,policy2': Comma-separated list of policies, such as 'RetryPolicy,UserAgentPolicy'" |
| 75 | + |
| 76 | +#### Additional ListEntitiesPageableTest command line options |
| 77 | + |
| 78 | +The options that are additionally available for `ListEntitiesPageableTest`: |
| 79 | + |
| 80 | +- `--count=100` - Number of table entities to list. Defaults to 100. |
| 81 | +- `--page-size=None` - Maximum number of entities to list per page. Default is None, which will return all possible results per page. |
| 82 | + |
| 83 | +## Example command |
| 84 | + |
| 85 | +```cmd |
| 86 | +(env) ~/core/corehttp> perfstress DownloadBinaryDataTest --use-entra-id --transport httpx --size=20480 --parallel=2 |
| 87 | +``` |
0 commit comments