5
5
#
6
6
import datetime
7
7
import logging
8
+ import threading
8
9
10
+ import redisbench_admin
9
11
from redisbench_admin .run .common import (
10
12
prepare_benchmark_parameters ,
11
13
)
14
+ from redisbench_admin .run .metrics import collect_cpu_data
12
15
from redisbench_admin .run .run import calculate_client_tool_duration_and_check
13
16
from redisbench_admin .run_remote .remote_helpers import (
14
17
benchmark_tools_sanity_check ,
@@ -46,6 +49,8 @@ def run_remote_client_tool(
46
49
warn_min_duration ,
47
50
client_ssh_port ,
48
51
private_key ,
52
+ collect_cpu_stats_thread = False ,
53
+ redis_conns = [],
49
54
):
50
55
(
51
56
benchmark_min_tool_version ,
@@ -105,6 +110,7 @@ def run_remote_client_tool(
105
110
tmp = local_bench_fname
106
111
local_bench_fname = "result.csv"
107
112
commands = [command_str ]
113
+ post_commands = []
108
114
if "ann" in benchmark_tool :
109
115
pkg_path = get_ann_remote_pkg_path (
110
116
client_public_ip , client_ssh_port , private_key , username
@@ -132,15 +138,25 @@ def run_remote_client_tool(
132
138
zip_results_command = "cd {} && zip -r {} results/*" .format (
133
139
results_outputdir , results_outputdir_zip
134
140
)
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 )
139
145
140
146
local_output_artifacts .append (website_outputdir_zip_local )
141
147
local_output_artifacts .append (results_outputdir_zip_local )
142
148
remote_output_artifacts .append (website_outputdir_zip )
143
149
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 ()
144
160
145
161
benchmark_start_time = datetime .datetime .now ()
146
162
# run the benchmark
@@ -154,6 +170,32 @@ def run_remote_client_tool(
154
170
client_ssh_port ,
155
171
)
156
172
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
+
157
199
benchmark_duration_seconds = calculate_client_tool_duration_and_check (
158
200
benchmark_end_time , benchmark_start_time , step_name , warn_min_duration
159
201
)
@@ -224,15 +266,15 @@ def run_remote_client_tool(
224
266
def setup_remote_benchmark_ann (
225
267
client_public_ip , username , private_key , client_ssh_port
226
268
):
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
+ # )
236
278
pkg_path = get_ann_remote_pkg_path (
237
279
client_public_ip , client_ssh_port , private_key , username
238
280
)
0 commit comments