Run RPS (Requests Per Second) tests
(rps_test_vectors, collection, batch_size=100)
| 772 | |
| 773 | |
| 774 | def run_rps_tests(rps_test_vectors, collection, batch_size=100): |
| 775 | """Run RPS (Requests Per Second) tests""" |
| 776 | print(f"Using {len(rps_test_vectors)} different test vectors for RPS testing") |
| 777 | |
| 778 | start_time_rps = time.time() |
| 779 | results = [] |
| 780 | |
| 781 | with ThreadPoolExecutor(max_workers=32) as executor: |
| 782 | futures = [] |
| 783 | for i in range(0, len(rps_test_vectors), batch_size): |
| 784 | batch = rps_test_vectors[i : i + batch_size] |
| 785 | futures.append(executor.submit(batch_ann_search, collection, batch)) |
| 786 | |
| 787 | for future in as_completed(futures): |
| 788 | try: |
| 789 | future.result() |
| 790 | results.append(True) |
| 791 | except Exception as e: |
| 792 | print(f"Error in RPS test: {e}") |
| 793 | results.append(False) |
| 794 | |
| 795 | end_time_rps = time.time() |
| 796 | actual_duration = end_time_rps - start_time_rps |
| 797 | |
| 798 | successful_requests = sum(results) * batch_size |
| 799 | failed_requests = (len(results) * batch_size) - successful_requests |
| 800 | total_requests = len(results) * batch_size |
| 801 | rps = successful_requests / actual_duration |
| 802 | |
| 803 | print("\nRPS Test Results:") |
| 804 | print(f"Total Requests: {total_requests}") |
| 805 | print(f"Successful Requests: {successful_requests}") |
| 806 | print(f"Failed Requests: {failed_requests}") |
| 807 | print(f"Test Duration: {actual_duration:.2f} seconds") |
| 808 | print(f"Requests Per Second (RPS): {rps:.2f}") |
| 809 | print(f"Success Rate: {(successful_requests / total_requests * 100):.2f}%") |
| 810 | |
| 811 | |
| 812 | def batch_ann_search(collection, vectors): |