Skip to content

Commit 26c5c00

Browse files
authored
Add excluded location configs to workload testing (#40704)
* Added Excluded Locations * Added envoy config generator * Add template * Updated Setup Document
1 parent 1a81d3f commit 26c5c00

13 files changed

+165
-152
lines changed

sdk/cosmos/azure-cosmos/tests/workloads/dev.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
99
- 32 GB RAM
1010
- Ubuntu
1111
- Accelerated networking
12-
2. Fork and clone this repository
13-
3. Go to azure cosmos folder
12+
1. Fork and clone this repository
13+
1. Go to azure cosmos folder
1414
- `cd azure-sdk-for-python/sdk/cosmos/azure-cosmos`
15-
4. Install the required packages and create virtual environment
15+
1. Install the required packages and create virtual environment
1616
- `sudo apt-get update`
1717
- `sudo apt-get install python3-pip`
1818
- `sudo apt-get install python3.12-venv`
1919
- `python3 -m venv azure-cosmosdb-sdk-environment`
2020
- `source azure-cosmosdb-sdk-environment/bin/activate`
2121
- `pip install -r dev_requirements.txt`
22-
5. Checkout the branch with the changes to test.
23-
6. Install azure-cosmos
22+
1. Checkout the branch with the changes to test.
23+
1. Install azure-cosmos
2424
- `pip install .`
25-
7. Go to workloads folder
25+
1. Go to workloads folder
2626
- `cd tests/workloads`
27-
8. Fill out relevant configs in `workload_configs.py`: key, host, etc
28-
9. Install envoy proxy https://www.envoyproxy.io/docs/envoy/latest/start/install
29-
10. Update envoy_simple_config.yaml to have the correct account info. Replace <> with account name.
30-
11. Go to envoy folder and start envoy
27+
1. Fill out relevant configs in `workload_configs.py`: key, host, etc
28+
1. Install envoy proxy https://www.envoyproxy.io/docs/envoy/latest/start/install
29+
1. Go to envoy folder and generate envoy configuration file using template. Template files are in `envoy/templates` directory. `<account_name>` is your Cosmos DB account name.
3130
- `cd envoy`
31+
- `./generate_envoy_config.sh <template_file_path> <output_envoy_config_file> <account_name>`
32+
1. Start envoy using the generated configuration file
3233
- `mkdir logs`
33-
- `envoy -c <envoy_file>.yaml --log-level debug --log-path logs/debug.txt`
34-
12. Run the setup workload to create the database and containers and insert data
34+
- `envoy -c <envoy_config_file>.yaml --log-level debug --log-path logs/debug.txt`
35+
1. Run the setup workload to create the database and containers and insert data
3536
- `python3 initial-setup.py`
36-
13. Run the scale workloads
37+
1. Run the scale workloads
3738
- `./run_workloads.sh <number of clients per workload>`
3839

3940
### Monitor Run
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Check if the correct number of arguments are provided
4+
if [ "$#" -ne 3 ]; then
5+
echo "Usage: $0 <template_file_path> <output_envoy_config_file> <account_name>"
6+
exit 1
7+
fi
8+
9+
# Assign arguments to variables
10+
template_file_path=$1
11+
output_envoy_config_file=$2
12+
account_name=$3
13+
14+
# Replace occurrences of "<>" with the account name and write to the new file
15+
sed "s/<>/$account_name/g" "$template_file_path" > "$output_envoy_config_file"
16+
17+
echo "Replacement complete. The result is saved in $output_envoy_config_file"

sdk/cosmos/azure-cosmos/tests/workloads/r_proxy_workload.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,32 @@
66
import aiohttp
77

88
from azure.cosmos import documents
9-
from workload_utils import create_logger, read_item_concurrently, query_items_concurrently
10-
from workload_configs import COSMOS_KEY, PREFERRED_LOCATIONS, CONCURRENT_REQUESTS, COSMOS_PROXY_URI, COSMOS_CONTAINER, \
11-
COSMOS_DATABASE, CONCURRENT_QUERIES
12-
from workload_configs import USE_MULTIPLE_WRITABLE_LOCATIONS
9+
from workload_utils import *
10+
from workload_configs import *
1311

1412
sys.path.append(r"/")
1513

1614
from azure.cosmos.aio import CosmosClient as AsyncClient
1715
from azure.core.pipeline.transport import AioHttpTransport
1816
import asyncio
1917

20-
from datetime import datetime
21-
2218
async def run_workload(client_id, client_logger):
2319
async with aiohttp.ClientSession(trust_env=True) as proxied_aio_http_session:
2420
connectionPolicy = documents.ConnectionPolicy()
2521
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
26-
2722
transport = AioHttpTransport(session=proxied_aio_http_session, session_owner=False)
28-
async with AsyncClient(COSMOS_PROXY_URI, COSMOS_KEY, preferred_locations=PREFERRED_LOCATIONS,
23+
async with AsyncClient(COSMOS_PROXY_URI, COSMOS_KEY, connection_policy=connectionPolicy,
24+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
2925
enable_diagnostics_logging=True, logger=client_logger, transport=transport,
30-
user_agent=str(client_id) + "-" + datetime.now().strftime(
31-
"%Y%m%d-%H%M%S"), connection_policy=connectionPolicy) as client:
26+
user_agent=get_user_agent(client_id)) as client:
3227
db = client.get_database_client(COSMOS_DATABASE)
3328
cont = db.get_container_client(COSMOS_CONTAINER)
3429
await asyncio.sleep(1)
3530

3631
while True:
3732
try:
38-
await read_item_concurrently(cont, CONCURRENT_REQUESTS)
39-
await query_items_concurrently(cont, CONCURRENT_QUERIES)
33+
await read_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
34+
await query_items_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
4035
except Exception as e:
4136
client_logger.info("Exception in application layer")
4237
client_logger.error(e)

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_proxy_workload.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import aiohttp
77

88
from azure.cosmos import documents
9-
from workload_utils import create_logger, upsert_item_concurrently, read_item_concurrently, query_items_concurrently
10-
from workload_configs import COSMOS_KEY, PREFERRED_LOCATIONS, USE_MULTIPLE_WRITABLE_LOCATIONS, \
11-
CONCURRENT_REQUESTS, COSMOS_PROXY_URI, COSMOS_CONTAINER, COSMOS_DATABASE, CONCURRENT_QUERIES
9+
from workload_utils import *
10+
from workload_configs import *
1211

1312
sys.path.append(r"/")
1413

@@ -17,27 +16,25 @@
1716
import asyncio
1817

1918
import time
20-
from datetime import datetime
2119

2220
async def run_workload(client_id, client_logger):
23-
connectionPolicy = documents.ConnectionPolicy()
24-
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
2521
async with aiohttp.ClientSession(trust_env=True) as proxied_aio_http_session:
26-
22+
connectionPolicy = documents.ConnectionPolicy()
23+
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
2724
transport = AioHttpTransport(session=proxied_aio_http_session, session_owner=False)
28-
async with AsyncClient(COSMOS_PROXY_URI, COSMOS_KEY, preferred_locations=PREFERRED_LOCATIONS,
25+
async with AsyncClient(COSMOS_PROXY_URI, COSMOS_KEY, connection_policy=connectionPolicy,
26+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
2927
enable_diagnostics_logging=True, logger=client_logger, transport=transport,
30-
user_agent=str(client_id) + "-" + datetime.now().strftime(
31-
"%Y%m%d-%H%M%S"), connection_policy=connectionPolicy) as client:
28+
user_agent=get_user_agent(client_id)) as client:
3229
db = client.get_database_client(COSMOS_DATABASE)
3330
cont = db.get_container_client(COSMOS_CONTAINER)
34-
time.sleep(1)
31+
await asyncio.sleep(1)
3532

3633
while True:
3734
try:
38-
await upsert_item_concurrently(cont, CONCURRENT_REQUESTS)
39-
await read_item_concurrently(cont, CONCURRENT_REQUESTS)
40-
await query_items_concurrently(cont, CONCURRENT_QUERIES)
35+
await upsert_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
36+
await read_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
37+
await query_items_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
4138
except Exception as e:
4239
client_logger.info("Exception in application layer")
4340
client_logger.error(e)

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_with_incorrect_client_workload.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,29 @@
44
import sys
55

66
from azure.cosmos import documents
7-
from workload_utils import upsert_item_concurrently, read_item_concurrently, query_items_concurrently, create_logger
8-
from workload_configs import (COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS,
9-
USE_MULTIPLE_WRITABLE_LOCATIONS,
10-
CONCURRENT_REQUESTS, COSMOS_DATABASE, COSMOS_CONTAINER,
11-
CONCURRENT_QUERIES)
7+
from workload_utils import *
8+
from workload_configs import *
129
sys.path.append(r"/")
1310

1411
from azure.cosmos.aio import CosmosClient as AsyncClient
1512
import asyncio
1613

17-
from datetime import datetime
18-
1914
async def run_workload(client_id, client_logger):
2015
connectionPolicy = documents.ConnectionPolicy()
2116
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
22-
client = AsyncClient(COSMOS_URI, COSMOS_KEY,
23-
enable_diagnostics_logging=True, logger=client_logger,
24-
user_agent=str(client_id) + "-" + datetime.now().strftime(
25-
"%Y%m%d-%H%M%S"), preferred_locations=PREFERRED_LOCATIONS,
26-
connection_policy=connectionPolicy)
17+
client = AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
18+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
19+
enable_diagnostics_logging=True, logger=client_logger,
20+
user_agent=get_user_agent(client_id))
2721
db = client.get_database_client(COSMOS_DATABASE)
2822
cont = db.get_container_client(COSMOS_CONTAINER)
2923
await asyncio.sleep(1)
3024

3125
while True:
3226
try:
33-
await upsert_item_concurrently(cont, CONCURRENT_REQUESTS)
34-
await read_item_concurrently(cont, CONCURRENT_REQUESTS)
35-
await query_items_concurrently(cont, CONCURRENT_QUERIES)
27+
await upsert_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
28+
await read_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
29+
await query_items_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
3630
except Exception as e:
3731
client_logger.info("Exception in application layer")
3832
client_logger.error(e)

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_workload.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@
44
import sys
55

66
from azure.cosmos import documents
7-
from workload_utils import upsert_item_concurrently, read_item_concurrently, query_items_concurrently, create_logger
8-
from workload_configs import (COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS, USE_MULTIPLE_WRITABLE_LOCATIONS,
9-
CONCURRENT_REQUESTS, COSMOS_DATABASE, COSMOS_CONTAINER, CONCURRENT_QUERIES)
7+
from workload_utils import *
8+
from workload_configs import *
109
sys.path.append(r"/")
1110

1211
from azure.cosmos.aio import CosmosClient as AsyncClient
1312
import asyncio
1413

15-
from datetime import datetime
16-
1714
async def run_workload(client_id, client_logger):
1815
connectionPolicy = documents.ConnectionPolicy()
1916
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
20-
async with AsyncClient(COSMOS_URI, COSMOS_KEY,
17+
async with AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
18+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
2119
enable_diagnostics_logging=True, logger=client_logger,
22-
user_agent=str(client_id) + "-" + datetime.now().strftime(
23-
"%Y%m%d-%H%M%S"), preferred_locations=PREFERRED_LOCATIONS,
24-
connection_policy=connectionPolicy) as client:
20+
user_agent=get_user_agent(client_id)) as client:
2521
db = client.get_database_client(COSMOS_DATABASE)
2622
cont = db.get_container_client(COSMOS_CONTAINER)
2723
await asyncio.sleep(1)
2824

2925
while True:
3026
try:
31-
await upsert_item_concurrently(cont, CONCURRENT_REQUESTS)
32-
await read_item_concurrently(cont, CONCURRENT_REQUESTS)
33-
await query_items_concurrently(cont, CONCURRENT_QUERIES)
27+
await upsert_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
28+
await read_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
29+
await query_items_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
3430
except Exception as e:
3531
client_logger.info("Exception in application layer")
3632
client_logger.error(e)

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_workload_sync.py

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,30 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
import os
44
import sys
5+
import time
56

6-
from workload_utils import create_logger, get_random_item
7-
from workload_configs import (COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS, USE_MULTIPLE_WRITABLE_LOCATIONS,
8-
CONCURRENT_REQUESTS, COSMOS_DATABASE, COSMOS_CONTAINER, CONCURRENT_QUERIES,
9-
PARTITION_KEY)
10-
7+
from workload_utils import *
8+
from workload_configs import *
119
sys.path.append(r"/")
1210

1311
from azure.cosmos import CosmosClient, documents
1412

15-
import time
16-
from datetime import datetime
17-
18-
def upsert_item(container, num_upserts):
19-
for _ in range(num_upserts):
20-
container.upsert_item(get_random_item(), etag=None, match_condition=None)
21-
22-
23-
def read_item(container, num_reads):
24-
for _ in range(num_reads):
25-
item = get_random_item()
26-
container.read_item(item["id"], item[PARTITION_KEY], etag=None, match_condition=None)
27-
28-
29-
def query_items(container, num_queries):
30-
for _ in range(num_queries):
31-
perform_query(container)
32-
33-
34-
def perform_query(container):
35-
random_item = get_random_item()
36-
results = container.query_items(query="SELECT * FROM c where c.id=@id and c.pk=@pk",
37-
parameters=[{"name": "@id", "value": random_item["id"]},
38-
{"name": "@pk", "value": random_item["pk"]}],
39-
partition_key=random_item[PARTITION_KEY])
40-
items = [item for item in results]
41-
42-
4313
def run_workload(client_id, client_logger):
4414
connectionPolicy = documents.ConnectionPolicy()
4515
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
46-
with CosmosClient(COSMOS_URI, COSMOS_KEY,
47-
enable_diagnostics_logging=True, logger=client_logger,
48-
user_agent=str(client_id) + "-" + datetime.now().strftime(
49-
"%Y%m%d-%H%M%S"), preferred_locations=PREFERRED_LOCATIONS,
50-
connection_policy=connectionPolicy) as client:
16+
with CosmosClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
17+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
18+
enable_diagnostics_logging=True, logger=client_logger,
19+
user_agent=get_user_agent(client_id)) as client:
5120
db = client.get_database_client(COSMOS_DATABASE)
5221
cont = db.get_container_client(COSMOS_CONTAINER)
5322
time.sleep(1)
5423

5524
while True:
5625
try:
57-
upsert_item(cont, CONCURRENT_REQUESTS)
58-
read_item(cont, CONCURRENT_REQUESTS)
59-
query_items(cont, CONCURRENT_QUERIES)
26+
upsert_item(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
27+
read_item(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
28+
query_items(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
6029
except Exception as e:
6130
client_logger.info("Exception in application layer")
6231
client_logger.error(e)

sdk/cosmos/azure-cosmos/tests/workloads/r_workload.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,28 @@
44
import sys
55

66
from azure.cosmos import documents
7-
from workload_utils import create_logger, read_item_concurrently, query_items_concurrently
8-
from workload_configs import (COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS, USE_MULTIPLE_WRITABLE_LOCATIONS,
9-
CONCURRENT_REQUESTS, COSMOS_CONTAINER, COSMOS_DATABASE, CONCURRENT_QUERIES)
10-
7+
from workload_utils import *
8+
from workload_configs import *
119
sys.path.append(r"/")
1210

1311
from azure.cosmos.aio import CosmosClient as AsyncClient
1412
import asyncio
1513

16-
from datetime import datetime
17-
1814
async def run_workload(client_id, client_logger):
19-
2015
connectionPolicy = documents.ConnectionPolicy()
2116
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
22-
async with AsyncClient(COSMOS_URI, COSMOS_KEY,
17+
async with AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
18+
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
2319
enable_diagnostics_logging=True, logger=client_logger,
24-
user_agent=str(client_id) + "-" + datetime.now().strftime(
25-
"%Y%m%d-%H%M%S"), preferred_locations=PREFERRED_LOCATIONS,
26-
connection_policy=connectionPolicy) as client:
20+
user_agent=get_user_agent(client_id)) as client:
2721
db = client.get_database_client(COSMOS_DATABASE)
2822
cont = db.get_container_client(COSMOS_CONTAINER)
2923
await asyncio.sleep(1)
3024

3125
while True:
3226
try:
33-
await read_item_concurrently(cont, CONCURRENT_REQUESTS)
34-
await query_items_concurrently(cont, CONCURRENT_QUERIES)
27+
await read_item_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_REQUESTS)
28+
await query_items_concurrently(cont, REQUEST_EXCLUDED_LOCATIONS, CONCURRENT_QUERIES)
3529
except Exception as e:
3630
client_logger.info("Exception in application layer")
3731
client_logger.error(e)

0 commit comments

Comments
 (0)