Skip to content

Commit 764837d

Browse files
committed
update stress test
1 parent 86f5761 commit 764837d

File tree

5 files changed

+49
-145
lines changed

5 files changed

+49
-145
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from hypha_rpc.sync import connect_to_server, login
2+
3+
4+
SERVER_URL = "https://hypha.aicell.io"
5+
WORKSPACE_NAME = "bioimageio-colab"
6+
7+
token = login({"server_url": SERVER_URL})
8+
server = connect_to_server(
9+
{"server_url": SERVER_URL, "token": token, "workspace": WORKSPACE_NAME}
10+
)
11+
12+
server.cleanup()

bioimageio_colab/create_workspace.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]
33

44
[project]
55
name = "bioimageio-colab"
6-
version = "0.2.7"
6+
version = "0.2.8"
77
readme = "README.md"
88
description = "Collaborative image annotation and model training with human in the loop."
99
dependencies = [

tests/stress_test.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
11
import argparse
22
import asyncio
3-
from time import sleep
3+
import os
4+
45
import numpy as np
56
from hypha_rpc import connect_to_server
67
from tifffile import imread
78

9+
810
SERVER_URL = "https://hypha.aicell.io"
911
WORKSPACE_NAME = "bioimageio-colab"
12+
CLIENT_ID = os.getenv("CLIENT_ID")
1013
SERVICE_ID = "microsam"
1114
MODEL_IDS = ["sam_vit_b", "sam_vit_b_lm", "sam_vit_b_em_organelles"]
1215
IMG_PATH = "./data/example_image.tif"
1316

1417

15-
async def run_client(
16-
client_id: int, image: np.ndarray, model_id: str, method_timeout: int = 300
17-
):
18-
print(f"Client {client_id} started", flush=True)
18+
async def compute_embedding(req_id, service, image):
19+
# Prepare image and model ID
20+
image_prep = image + np.random.normal(0, 0.1, image.shape)
21+
model_id = MODEL_IDS[np.random.randint(0, len(MODEL_IDS))]
22+
23+
print(f"Sending request {req_id + 1}")
24+
await service.compute_embedding(
25+
image=image_prep,
26+
model_id=model_id,
27+
)
28+
print(f"Request {req_id} finished")
29+
30+
31+
async def stress_test(num_requests: int, method_timeout: int = 30):
32+
# Connect to the server and get the compute service
33+
service_client_str = f"{CLIENT_ID}:" if CLIENT_ID else ""
34+
compute_service_id = f"{WORKSPACE_NAME}/{service_client_str}{SERVICE_ID}"
35+
print(f"Compute service ID: {compute_service_id}")
1936
client = await connect_to_server(
2037
{"server_url": SERVER_URL, "method_timeout": method_timeout}
2138
)
22-
service = await client.get_service(
23-
f"{WORKSPACE_NAME}/{SERVICE_ID}", {"mode": "random"}
24-
)
25-
await service.compute_embedding(model_id=model_id, image=image)
26-
print(f"Client {client_id} finished", flush=True)
27-
39+
service = await client.get_service(compute_service_id, {"mode": "first"})
2840

29-
async def stress_test(num_clients: int):
41+
# Load the image
3042
image = imread(IMG_PATH)
43+
44+
# Send requests
3145
tasks = []
32-
for client_id in range(num_clients):
33-
sleep(0.1)
34-
model_id = MODEL_IDS[np.random.randint(0, len(MODEL_IDS))]
35-
tasks.append(run_client(client_id=client_id, image=image, model_id=model_id))
46+
for req_id in range(num_requests):
47+
tasks.append(compute_embedding(req_id, service, image))
3648
await asyncio.gather(*tasks)
37-
print("All clients finished")
49+
50+
print("All requests completed successfully.")
3851

3952

4053
if __name__ == "__main__":
4154
parser = argparse.ArgumentParser()
42-
parser.add_argument("--num_clients", type=int, default=50)
55+
parser.add_argument(
56+
"--num_requests", type=int, default=30, help="Number of requests"
57+
)
4358
args = parser.parse_args()
4459

45-
asyncio.run(stress_test(args.num_clients))
60+
asyncio.run(stress_test(args.num_requests))

tests/test_model_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import requests
33
from hypha_rpc.sync import connect_to_server
44
from tifffile import imread
5+
import os
56

67
SERVER_URL = "https://hypha.aicell.io"
78
WORKSPACE_NAME = "bioimageio-colab"
89
SERVICE_ID = "microsam"
9-
CLIENT_ID = ""
10+
CLIENT_ID = os.getenv("CLIENT_ID")
1011
MODEL_IDS = ["sam_vit_b", "sam_vit_b_lm", "sam_vit_b_em_organelles"]
1112
IMG_PATH = "./data/example_image.tif"
1213

0 commit comments

Comments
 (0)