55#
66import datetime
77import logging
8+ import threading
89
10+ import redisbench_admin
911from redisbench_admin .run .common import (
1012 prepare_benchmark_parameters ,
1113)
14+ from redisbench_admin .run .metrics import collect_cpu_data
1215from redisbench_admin .run .run import calculate_client_tool_duration_and_check
1316from redisbench_admin .run_remote .remote_helpers import (
1417 benchmark_tools_sanity_check ,
@@ -46,6 +49,8 @@ def run_remote_client_tool(
4649 warn_min_duration ,
4750 client_ssh_port ,
4851 private_key ,
52+ collect_cpu_stats_thread = False ,
53+ redis_conns = [],
4954):
5055 (
5156 benchmark_min_tool_version ,
@@ -105,6 +110,7 @@ def run_remote_client_tool(
105110 tmp = local_bench_fname
106111 local_bench_fname = "result.csv"
107112 commands = [command_str ]
113+ post_commands = []
108114 if "ann" in benchmark_tool :
109115 pkg_path = get_ann_remote_pkg_path (
110116 client_public_ip , client_ssh_port , private_key , username
@@ -132,15 +138,25 @@ def run_remote_client_tool(
132138 zip_results_command = "cd {} && zip -r {} results/*" .format (
133139 results_outputdir , results_outputdir_zip
134140 )
135- commands .append (mkdir_command )
136- commands .append (create_website_command )
137- commands .append (zip_website_command )
138- commands .append (zip_results_command )
141+ post_commands .append (mkdir_command )
142+ post_commands .append (create_website_command )
143+ post_commands .append (zip_website_command )
144+ post_commands .append (zip_results_command )
139145
140146 local_output_artifacts .append (website_outputdir_zip_local )
141147 local_output_artifacts .append (results_outputdir_zip_local )
142148 remote_output_artifacts .append (website_outputdir_zip )
143149 remote_output_artifacts .append (results_outputdir_zip )
150+ cpu_stats_thread = None
151+ if collect_cpu_stats_thread is True :
152+ # run the benchmark
153+ cpu_stats_thread = threading .Thread (
154+ target = collect_cpu_data ,
155+ args = (redis_conns , 5.0 , 1.0 ),
156+ )
157+ redisbench_admin .run .metrics .BENCHMARK_RUNNING_GLOBAL = True
158+ logging .info ("Starting CPU collecing thread" )
159+ cpu_stats_thread .start ()
144160
145161 benchmark_start_time = datetime .datetime .now ()
146162 # run the benchmark
@@ -154,6 +170,32 @@ def run_remote_client_tool(
154170 client_ssh_port ,
155171 )
156172 benchmark_end_time = datetime .datetime .now ()
173+ if cpu_stats_thread is not None :
174+ logging .info ("Stopping CPU collecting thread" )
175+ redisbench_admin .run .metrics .BENCHMARK_RUNNING_GLOBAL = False
176+ cpu_stats_thread .join ()
177+ logging .info ("CPU collecting thread stopped" )
178+ if len (post_commands ) > 0 :
179+ res = execute_remote_commands (
180+ client_public_ip , username , private_key , post_commands , client_ssh_port
181+ )
182+ recv_exit_status , _ , _ = res [0 ]
183+
184+ if recv_exit_status != 0 :
185+ logging .error (
186+ "Exit status of remote command execution {}. Printing stdout and stderr" .format (
187+ recv_exit_status
188+ )
189+ )
190+ stderr , stdout = print_commands_outputs (post_commands , True , res )
191+ else :
192+ logging .info (
193+ "Remote process exited normally. Exit code {}. Printing stdout." .format (
194+ recv_exit_status
195+ )
196+ )
197+ stderr , stdout = print_commands_outputs (post_commands , False , res )
198+
157199 benchmark_duration_seconds = calculate_client_tool_duration_and_check (
158200 benchmark_end_time , benchmark_start_time , step_name , warn_min_duration
159201 )
@@ -224,15 +266,15 @@ def run_remote_client_tool(
224266def setup_remote_benchmark_ann (
225267 client_public_ip , username , private_key , client_ssh_port
226268):
227- commands = [
228- "sudo apt install python3-pip -y" ,
229- "sudo pip3 install redisbench-admin>=0.7.0" ,
230- ]
231- # last argument (get_pty) needs to be set to true
232- # check: https://stackoverflow.com/questions/5785353/paramiko-and-sudo
233- execute_remote_commands (
234- client_public_ip , username , private_key , commands , client_ssh_port , True
235- )
269+ # commands = [
270+ # "sudo apt install python3-pip -y",
271+ # "sudo pip3 install redisbench-admin>=0.7.0",
272+ # ]
273+ # # last argument (get_pty) needs to be set to true
274+ # # check: https://stackoverflow.com/questions/5785353/paramiko-and-sudo
275+ # execute_remote_commands(
276+ # client_public_ip, username, private_key, commands, client_ssh_port, True
277+ # )
236278 pkg_path = get_ann_remote_pkg_path (
237279 client_public_ip , client_ssh_port , private_key , username
238280 )
0 commit comments