Skip to content

Commit

Permalink
Add profiling test for usage in multi-threading environment
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmith023 committed Jun 6, 2024
1 parent f65a9cc commit 4dccd1a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ image.png
.vscode/
scratch/

*-test.sh
*-test.sh
*.hdf5
42 changes: 41 additions & 1 deletion profiling/test_profiling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# run:
# - profiling: pytest -m profiling profiling/test_profiling.py --profile-svg
# - benchmark: pytest profiling/test_profiling.py --benchmark-only --benchmark-disable-gc

import concurrent.futures
import math
from typing import Any, List
import uuid
Expand Down Expand Up @@ -231,6 +231,42 @@ def test_list_value_properties(client: weaviate.WeaviateClient) -> None:
assert len(objs) == 100


def test_multithreaded_queries(client: weaviate.WeaviateClient) -> None:
name = "TestProfileMultithreadedQueries"
client.collections.delete(name)

col = client.collections.create(
name=name,
properties=[
Property(name="index", data_type=DataType.INT),
],
vectorizer_config=Configure.Vectorizer.none(),
)

col = client.collections.get(name)

col.data.insert_many([{"index": i} for i in range(1000)])

def query_objects() -> None:
for _ in range(100):
objs = col.query.fetch_objects(
limit=1000,
include_vector=False,
return_properties=["index"],
return_metadata=None,
)
assert len(objs.objects) == 1000

threads: List[concurrent.futures.Future] = []
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
threads.extend([executor.submit(query_objects) for _ in range(4)])

for thread in threads:
thread.result()

client.collections.delete(name)


def test_benchmark_get_vector(benchmark: Any, client: weaviate.WeaviateClient) -> None:
benchmark(test_get_vector, client)

Expand All @@ -253,3 +289,7 @@ def test_benchmark_blob_properties(benchmark: Any, client: weaviate.WeaviateClie

def test_benchmark_list_value_properties(benchmark: Any, client: weaviate.WeaviateClient) -> None:
benchmark(test_list_value_properties, client)


def test_benchmark_multithreaded_queries(benchmark: Any, client: weaviate.WeaviateClient) -> None:
benchmark(test_multithreaded_queries, client)

0 comments on commit 4dccd1a

Please sign in to comment.