77import ruamel .yaml
88from ruamel .yaml .scalarstring import DoubleQuotedScalarString
99
10+
1011def calculate_rate_limit (p50_value ):
1112 if p50_value < 1000 :
1213 return 100
@@ -15,23 +16,26 @@ def calculate_rate_limit(p50_value):
1516 else :
1617 return 10000
1718
18- def create_new_test_config (original_config_path , new_config_path , test_name , new_test_name , p50_value ):
19+
20+ def create_new_test_config (
21+ original_config_path , new_config_path , test_name , new_test_name , p50_value
22+ ):
1923 # Check if the original configuration file exists
2024 if not os .path .exists (original_config_path ):
2125 return False # Indicate failure
2226
2327 # Load the original test configuration with ruamel.yaml
2428 yaml = ruamel .yaml .YAML ()
2529 yaml .preserve_quotes = True # Preserve quotes in scalar values
26- with open (original_config_path , 'r' ) as file :
30+ with open (original_config_path , "r" ) as file :
2731 config = yaml .load (file )
2832
2933 # Calculate the total desired rate limit
3034 total_rate_limit = calculate_rate_limit (p50_value )
3135
3236 # Calculate per-connection rate limit
3337 # Extract the original arguments
34- original_arguments = config [' clientconfig' ][ ' arguments' ]
38+ original_arguments = config [" clientconfig" ][ " arguments" ]
3539
3640 # Convert to string if necessary
3741 if not isinstance (original_arguments , str ):
@@ -46,11 +50,15 @@ def create_new_test_config(original_config_path, new_config_path, test_name, new
4650 clients_per_thread = 50 # Default value
4751 threads = 4 # Default value
4852
49- clients_match = re .search (r'(?:-c|--clients)(?:[=\s]+)(\d+)' , original_arguments_str )
53+ clients_match = re .search (
54+ r"(?:-c|--clients)(?:[=\s]+)(\d+)" , original_arguments_str
55+ )
5056 if clients_match :
5157 clients_per_thread = int (clients_match .group (1 ))
5258
53- threads_match = re .search (r'(?:-t|--threads)(?:[=\s]+)(\d+)' , original_arguments_str )
59+ threads_match = re .search (
60+ r"(?:-t|--threads)(?:[=\s]+)(\d+)" , original_arguments_str
61+ )
5462 if threads_match :
5563 threads = int (threads_match .group (1 ))
5664
@@ -61,28 +69,35 @@ def create_new_test_config(original_config_path, new_config_path, test_name, new
6169 per_connection_rate_limit = max (1 , int (total_rate_limit / total_connections ))
6270
6371 # Remove existing rate limit arguments using regex
64- new_arguments = re .sub (r'--rate(?:-limit(?:ing)?)?(?:\s+\S+)?' , '' , original_arguments_str )
72+ new_arguments = re .sub (
73+ r"--rate(?:-limit(?:ing)?)?(?:\s+\S+)?" , "" , original_arguments_str
74+ )
6575
6676 # Append the new '--rate-limiting' argument and its value
67- new_arguments = f'{ new_arguments .strip ()} --rate-limiting { per_connection_rate_limit } '
77+ new_arguments = (
78+ f"{ new_arguments .strip ()} --rate-limiting { per_connection_rate_limit } "
79+ )
6880
6981 # Update the test name to reflect the new test
70- config [' name' ] = new_test_name
71- config [' description' ] += f" Rate limited to { total_rate_limit } ops/sec."
82+ config [" name" ] = new_test_name
83+ config [" description" ] += f" Rate limited to { total_rate_limit } ops/sec."
7284
7385 # Update the arguments in the config
74- config [' clientconfig' ][ ' arguments' ] = DoubleQuotedScalarString (new_arguments )
86+ config [" clientconfig" ][ " arguments" ] = DoubleQuotedScalarString (new_arguments )
7587
7688 # Ensure the destination directory exists
7789 os .makedirs (os .path .dirname (new_config_path ), exist_ok = True )
7890
7991 # Save the new test configuration
80- with open (new_config_path , 'w' ) as file :
92+ with open (new_config_path , "w" ) as file :
8193 yaml .dump (config , file )
8294
83- print (f"Created new test configuration for '{ test_name } ' with total rate limit { total_rate_limit } ops/sec and per-connection rate limit { per_connection_rate_limit } ops/sec." )
95+ print (
96+ f"Created new test configuration for '{ test_name } ' with total rate limit { total_rate_limit } ops/sec and per-connection rate limit { per_connection_rate_limit } ops/sec."
97+ )
8498 return True # Indicate success
8599
100+
86101def main ():
87102 parser = argparse .ArgumentParser (
88103 description = "Create latency benchmarks" ,
@@ -141,40 +156,47 @@ def main():
141156 # Execute the TS.REVRANGE command
142157 # "-" and "+" denote the minimal and maximal timestamps
143158 result = rts .execute_command ("TS.REVRANGE" , ts_key , "-" , "+" )
144-
159+
145160 # Check if result is not empty
146161 if result :
147162 # Extract values and convert to floats
148163 values = [float (value ) for timestamp , value in result ]
149164 # Compute the median (p50)
150165 p50_value = np .median (values )
151-
166+
152167 # Output the results
153168 print (f"Results for test case '{ test_name } ': p50 rate = { p50_value } " )
154169 rate = calculate_rate_limit (p50_value )
155170
156- original_config_path = f'../redis_benchmarks_specification/test-suites/{ test_name } .yml' # Original test config file
157- new_test_name = f'latency-rate-limited-{ rate } _qps-{ test_name } '
158- new_config_path = f'../redis_benchmarks_specification/test-suites/{ new_test_name } .yaml' # New test config file
159- success = create_new_test_config (original_config_path , new_config_path , test_name , new_test_name , p50_value )
171+ original_config_path = f"../redis_benchmarks_specification/test-suites/{ test_name } .yml" # Original test config file
172+ new_test_name = f"latency-rate-limited-{ rate } _qps-{ test_name } "
173+ new_config_path = f"../redis_benchmarks_specification/test-suites/{ new_test_name } .yaml" # New test config file
174+ success = create_new_test_config (
175+ original_config_path ,
176+ new_config_path ,
177+ test_name ,
178+ new_test_name ,
179+ p50_value ,
180+ )
160181 if not success :
161182 failed_files .append (test_name )
162183 else :
163184 print (f"No data available for test case '{ test_name } '." )
164185 failed_files .append (test_name )
165-
186+
166187 except redis .exceptions .ResponseError as e :
167188 print (f"Error retrieving data for test case '{ test_name } ': { e } " )
168189 failed_files .append (test_name )
169190 except Exception as e :
170191 print (f"An error occurred while processing test case '{ test_name } ': { e } " )
171192 failed_files .append (test_name )
172-
193+
173194 # At the end, print out the list of failed files if any
174195 if failed_files :
175196 print ("\n The following test cases had missing configuration files or errors:" )
176197 for test_name in failed_files :
177198 print (f"- { test_name } " )
178199
200+
179201if __name__ == "__main__" :
180202 main ()
0 commit comments