MCPcopy Create free account
hub / github.com/cosdata/cosdata / run_rps_tests

Function run_rps_tests

tests/test-sparse-vector.py:425–477  ·  view source on GitHub ↗

Run RPS (Requests Per Second) tests

(
    rps_test_vectors,
    collection,
    batch_size=100,
    top_k=10,
    early_terminate_threshold=0.0,
)

Source from the content-addressed store, hash-verified

423
424
425def run_rps_tests(
426 rps_test_vectors,
427 collection,
428 batch_size=100,
429 top_k=10,
430 early_terminate_threshold=0.0,
431):
432 """Run RPS (Requests Per Second) tests"""
433 print(f"Using {len(rps_test_vectors)} different test vectors for RPS testing")
434
435 start_time_rps = time.time()
436 results = []
437
438 with ThreadPoolExecutor(max_workers=8) as executor:
439 futures = []
440 for i in range(0, len(rps_test_vectors), batch_size):
441 batch = [
442 format_for_server_query(vector)
443 for vector in rps_test_vectors[i : i + batch_size]
444 ]
445 futures.append(
446 executor.submit(
447 batch_ann_search,
448 collection,
449 batch,
450 top_k,
451 early_terminate_threshold,
452 )
453 )
454
455 for future in as_completed(futures):
456 try:
457 future.result()
458 results.append(True)
459 except Exception as e:
460 print(f"Error in RPS test: {e}")
461 results.append(False)
462
463 end_time_rps = time.time()
464 actual_duration = end_time_rps - start_time_rps
465
466 successful_requests = sum(results) * batch_size
467 failed_requests = (len(results) * batch_size) - successful_requests
468 total_requests = len(results) * batch_size
469 rps = successful_requests / actual_duration
470
471 print("\nRPS Test Results:")
472 print(f"Total Requests: {total_requests}")
473 print(f"Successful Requests: {successful_requests}")
474 print(f"Failed Requests: {failed_requests}")
475 print(f"Test Duration: {actual_duration:.2f} seconds")
476 print(f"Requests Per Second (RPS): {rps:.2f}")
477 print(f"Success Rate: {(successful_requests / total_requests * 100):.2f}%")
478
479
480def main():

Callers 1

mainFunction · 0.70

Calls 2

format_for_server_queryFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected