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