1313import sys
1414import tempfile
1515import datetime
16+ import traceback
1617
1718import redis
1819import wget
20+ from rediscluster import RedisCluster
1921
2022from redisbench_admin .environments .oss_cluster import spin_up_local_redis_cluster
2123from redisbench_admin .profilers .perf import Perf
3133 extract_test_feasible_setups ,
3234 get_setup_type_and_primaries_count ,
3335)
34- from redisbench_admin .run_local .args import PROFILE_FREQ
36+ from redisbench_admin .run_local .args import PROFILE_FREQ , MAX_PROFILERS_PER_TYPE
3537from redisbench_admin .utils .benchmark_config import (
3638 prepare_benchmark_definitions ,
3739 extract_benchmark_tool_settings ,
@@ -200,56 +202,74 @@ def run_local_command_logic(args):
200202 dbdir_folder , temporary_dir
201203 )
202204 )
203-
204- check_dataset_local_requirements (
205- benchmark_config , temporary_dir , dirname
206- )
207-
208205 (
209206 redis_configuration_parameters ,
210207 _ ,
211208 ) = extract_redis_dbconfig_parameters (
212209 benchmark_config , "dbconfig"
213210 )
214211 cluster_api_enabled = False
215- if setup_type == "oss-standalone" :
216- redis_processes = spin_up_local_redis (
212+
213+ if setup_type == "oss-cluster" :
214+ cluster_api_enabled = True
215+ # pass
216+ redis_processes = spin_up_local_redis_cluster (
217217 temporary_dir ,
218+ shard_count ,
218219 args .port ,
219220 local_module_file ,
220221 redis_configuration_parameters ,
221222 dbdir_folder ,
222223 )
223-
224224 for redis_process in redis_processes :
225225 if is_process_alive (redis_process ) is False :
226226 raise Exception (
227227 "Redis process is not alive. Failing test."
228228 )
229-
229+ # we use node 0 for the checks
230230 r = redis .StrictRedis (port = args .port )
231+ r_conns = []
232+ for p in range (args .port , args .port + shard_count ):
233+ redis .StrictRedis (port = p ).execute_command (
234+ "CLUSTER SAVECONFIG"
235+ )
231236
232- if setup_type == "oss-cluster" :
233- cluster_api_enabled = True
234- # pass
235- redis_processes = spin_up_local_redis_cluster (
237+ check_dataset_local_requirements (
238+ benchmark_config ,
239+ temporary_dir ,
240+ dirname ,
241+ "./datasets" ,
242+ "dbconfig" ,
243+ shard_count ,
244+ cluster_api_enabled ,
245+ )
246+
247+ if setup_type == "oss-standalone" :
248+ redis_processes = spin_up_local_redis (
236249 temporary_dir ,
237- shard_count ,
238250 args .port ,
239251 local_module_file ,
240252 redis_configuration_parameters ,
241253 dbdir_folder ,
242254 )
255+
243256 for redis_process in redis_processes :
244257 if is_process_alive (redis_process ) is False :
245258 raise Exception (
246259 "Redis process is not alive. Failing test."
247260 )
248- # we use node 0 for the checks
261+
249262 r = redis .StrictRedis (port = args .port )
250- r_conns = []
263+
264+ if setup_type == "oss-cluster" :
265+ startup_nodes = []
251266 for p in range (args .port , args .port + shard_count ):
252- r_conns .append (redis .StrictRedis (port = p ))
267+ primary_conn = redis .StrictRedis (port = p )
268+ primary_conn .execute_command ("DEBUG RELOAD NOSAVE" )
269+ r_conns .append (primary_conn )
270+ startup_nodes .append (
271+ {"host" : "127.0.0.1" , "port" : "{}" .format (p )}
272+ )
253273 if clusterconfig is not None :
254274 if "init_commands" in clusterconfig :
255275 for command_group in clusterconfig ["init_commands" ]:
@@ -302,6 +322,16 @@ def run_local_command_logic(args):
302322 ],
303323 )
304324 )
325+
326+ rc = RedisCluster (
327+ startup_nodes = startup_nodes , decode_responses = True
328+ )
329+ cluster_info = rc .cluster_info ()
330+ logging .info (
331+ "Cluster info after initialization: {}." .format (
332+ cluster_info
333+ )
334+ )
305335 stdout = r .execute_command ("info modules" )
306336 (
307337 module_names ,
@@ -365,7 +395,9 @@ def run_local_command_logic(args):
365395 logging .info ("Profilers are enabled" )
366396 total_involved_processes = len (redis_processes )
367397 _ , profilers_map = get_profilers_map (
368- profilers_list , total_involved_processes
398+ profilers_list ,
399+ total_involved_processes ,
400+ MAX_PROFILERS_PER_TYPE ,
369401 )
370402 for (
371403 profiler_name ,
@@ -374,6 +406,10 @@ def run_local_command_logic(args):
374406 for setup_process_number , redis_process in enumerate (
375407 redis_processes
376408 ):
409+ if (setup_process_number + 1 ) > len (
410+ profiler_obj_arr
411+ ):
412+ continue
377413 profiler_obj = profiler_obj_arr [
378414 setup_process_number
379415 ]
@@ -447,49 +483,47 @@ def run_local_command_logic(args):
447483 profiler_name ,
448484 profiler_obj_arr ,
449485 ) in profilers_map .items ():
450- for setup_process_number , redis_process in enumerate (
451- redis_processes
486+ for setup_process_number , profiler_obj in enumerate (
487+ profiler_obj_arr
452488 ):
453- profiler_obj = profiler_obj_arr [
454- setup_process_number
455- ]
456- setup_process_number = setup_process_number + 1
457489 logging .info (
458490 "Stopping profiler {} for Process {} of {}: pid {}" .format (
459491 profiler_name ,
460492 setup_process_number ,
461493 total_involved_processes ,
462- redis_process .pid ,
494+ profiler_obj .pid ,
463495 )
464496 )
465497
466- profiler_obj .stop_profile ()
467-
468- # Generate:
469- # - artifact with Flame Graph SVG
470- # - artifact with output graph image in PNG format
471- # - artifact with top entries in text form
472- (
473- profile_res ,
474- profile_res_artifacts_map ,
475- ) = profiler_obj .generate_outputs (
476- test_name ,
477- details = collection_summary_str ,
478- binary = dso ,
479- primary_id = setup_process_number ,
480- total_primaries = total_involved_processes ,
481- )
498+ profile_res = profiler_obj .stop_profile ()
482499 if profile_res is True :
483- logging .info (
484- "Profiler {} for pid {} ran successfully and generated {} artifacts." .format (
485- profiler_name ,
486- redis_process .pid ,
487- len (profile_res_artifacts_map .values ()),
488- )
489- )
490- overall_artifacts_map .update (
491- profile_res_artifacts_map
500+ # Generate:
501+ # - artifact with Flame Graph SVG
502+ # - artifact with output graph image in PNG format
503+ # - artifact with top entries in text form
504+ (
505+ profile_res ,
506+ profile_res_artifacts_map ,
507+ ) = profiler_obj .generate_outputs (
508+ test_name ,
509+ details = collection_summary_str ,
510+ binary = dso ,
511+ primary_id = (setup_process_number + 1 ),
512+ total_primaries = total_involved_processes ,
492513 )
514+ if profile_res is True :
515+ logging .info (
516+ "Profiler {} for pid {} ran successfully and generated {} artifacts." .format (
517+ profiler_name ,
518+ profiler_obj .pid ,
519+ len (
520+ profile_res_artifacts_map .values ()
521+ ),
522+ )
523+ )
524+ overall_artifacts_map .update (
525+ profile_res_artifacts_map
526+ )
493527
494528 for (
495529 artifact_name ,
@@ -537,9 +571,10 @@ def run_local_command_logic(args):
537571 except :
538572 return_code |= 1
539573 logging .critical (
540- "Some unexpected exception was caught during remote work. Failing test...."
574+ "Some unexpected exception was caught during local work. Failing test...."
541575 )
542576 logging .critical (sys .exc_info ())
577+ logging .critical ("Traceback: {}" .format (traceback .format_exc ()))
543578 # tear-down
544579 logging .info ("Tearing down setup" )
545580 for redis_process in redis_processes :
@@ -598,22 +633,33 @@ def check_compatible_system_and_kernel_and_prepare_profile(args):
598633 return res
599634
600635
601- def get_profilers_map (profilers_list , total_involved_processes ):
636+ def get_profilers_map (profilers_list , total_involved_processes , max_profilers = 1 ):
602637 profilers_map = {}
603638 res = True
604639 for profiler_name in profilers_list :
605640 try :
606641 profilers_map [profiler_name ] = []
607642 if "perf:" in profiler_name :
608- logging .info ("Preparing perf (a.k.a. perf_events ) profiler" )
609- for _ in range (total_involved_processes ):
610- perf = Perf ()
611- profilers_map [profiler_name ].append (perf )
643+ for profilers_per_type in range (1 , total_involved_processes + 1 ):
644+ if profilers_per_type <= max_profilers :
645+ logging .info (
646+ "Preparing perf (a.k.a. perf_events ) profiler for proc {} of {}" .format (
647+ profilers_per_type , total_involved_processes
648+ )
649+ )
650+ perf = Perf ()
651+ profilers_map [profiler_name ].append (perf )
612652 if "vtune" in profiler_name :
613- logging .info ("Preparing Intel(R) VTune(TM) profiler" )
614- for _ in range (total_involved_processes ):
615- vtune = Vtune ()
616- profilers_map [profiler_name ].append (vtune )
653+
654+ for profilers_per_type in range (total_involved_processes ):
655+ logging .info (
656+ "Preparing Intel(R) VTune(TM) profiler for proc {} of {}" .format (
657+ profilers_per_type , total_involved_processes
658+ )
659+ )
660+ if profilers_per_type <= max_profilers :
661+ vtune = Vtune ()
662+ profilers_map [profiler_name ].append (vtune )
617663 except Exception as e :
618664 logging .error (
619665 "Detected error while trying to prepare profiler named {}. Error: {}" .format (
0 commit comments