@@ -930,6 +930,146 @@ def run_ycsb(
930930 run_local_shell_command (cmd_args , quiet = True , cwd = cwd , stderr = stderr_file )
931931
932932
933+ def run_mongo_ycsb (
934+ hosts : List [str ],
935+ database : str ,
936+ action : str ,
937+ workload : str ,
938+ items : int ,
939+ workers : int ,
940+ target : int ,
941+ port : int = 27017 ,
942+ instance : int = 0 ,
943+ username : Optional [str ] = None ,
944+ password : Optional [str ] = None ,
945+ replica_set_name : Optional [str ] = None ,
946+ ycsb_client : str = "mongodb" ,
947+ write_concern : str = "majority" ,
948+ batch_size : int = 1 ,
949+ requestdistribution : str = "zipfian" ,
950+ fieldlength : int = 1024 ,
951+ fieldcount : int = 10 ,
952+ upsert : bool = False ,
953+ write_all_fields : bool = True ,
954+ journal_ack : bool = True ,
955+ read_preference : Optional [str ] = None ,
956+ read_concern : Optional [str ] = None ,
957+ max_pool_size : Optional [int ] = None ,
958+ ops : Optional [int ] = None ,
959+ execution_time : Optional [int ] = None ,
960+ timeseries : int = 0 ,
961+ phase_params : Optional [dict ] = None ,
962+ insert_test_params : Optional [dict ] = None ,
963+ soe_params : Optional [dict ] = None ,
964+ ycsb_jvm_args : Optional [str ] = None ,
965+ measurement_type : Optional [str ] = None ,
966+ histogram_buckets : Optional [int ] = None ,
967+ histogram_bucket_size : Optional [int ] = None ,
968+ verbose_histogram : bool = False ,
969+ ycsb_status_output : bool = True ,
970+ ):
971+ seeds = "," .join (f"{ h } :{ port } " for h in hosts )
972+
973+ cred = ""
974+ if username and password :
975+ cred = (
976+ f"{ urllib .parse .quote (username , safe = '' )} :"
977+ f"{ urllib .parse .quote (password , safe = '' )} @"
978+ )
979+
980+ uri_params = [f"w={ write_concern } " ]
981+ if replica_set_name :
982+ uri_params .append (f"replicaSet={ replica_set_name } " )
983+ if not journal_ack :
984+ uri_params .append ("journal=false" )
985+ if read_preference :
986+ uri_params .append (f"readPreference={ read_preference } " )
987+ if read_concern :
988+ uri_params .append (f"readConcernLevel={ read_concern } " )
989+ if max_pool_size :
990+ uri_params .append (f"maxPoolSize={ max_pool_size } " )
991+ mongo_url = f"mongodb://{ cred } { seeds } /{ database } ?" + "&" .join (uri_params )
992+
993+ parameters = [
994+ f"target={ target } " ,
995+ f"fieldlength={ fieldlength } " ,
996+ f"fieldcount={ fieldcount } " ,
997+ f"requestdistribution={ requestdistribution } " ,
998+ f"writeallfields={ str (write_all_fields ).lower ()} " ,
999+ f"mongodb.url={ mongo_url } " ,
1000+ f"mongodb.database={ database } " ,
1001+ f"mongodb.batchsize={ batch_size } " ,
1002+ f"mongodb.writeConcern={ write_concern } " ,
1003+ f"mongodb.upsert={ str (upsert ).lower ()} " ,
1004+ f"exportfile=ycsb_{ action } _{ instance } _{ database } .log" ,
1005+ ]
1006+
1007+ if ops is not None :
1008+ parameters += [f"operationcount={ ops } " ]
1009+ if execution_time is not None :
1010+ parameters += [f"maxexecutiontime={ execution_time } " ]
1011+ if ycsb_jvm_args is not None :
1012+ parameters += [f"jvm-args='{ ycsb_jvm_args } '" ]
1013+
1014+ if timeseries :
1015+ parameters += ["measurementtype=timeseries" ]
1016+ elif measurement_type :
1017+ parameters += [f"measurementtype={ measurement_type } " ]
1018+ if histogram_buckets :
1019+ parameters += [f"histogram.buckets={ histogram_buckets } " ]
1020+ if histogram_bucket_size :
1021+ parameters += [f"histogram.bucket.size={ histogram_bucket_size } " ]
1022+ if verbose_histogram :
1023+ parameters += ["measurement.histogram.verbose=true" ]
1024+
1025+ if soe_params :
1026+ parameters += [
1027+ f"totalrecordcount={ items } " ,
1028+ f"recordcount={ soe_params ['recorded_load_cache_size' ]} " ,
1029+ f"insertstart={ soe_params ['insertstart' ]} " ,
1030+ ]
1031+ elif phase_params :
1032+ parameters += [
1033+ f"totalrecordcount={ items } " ,
1034+ f"recordcount={ phase_params ['inserts_per_workerinstance' ]} " ,
1035+ f"insertstart={ phase_params ['insertstart' ]} " ,
1036+ ]
1037+ elif insert_test_params :
1038+ parameters += [
1039+ f"recordcount={ insert_test_params ['recordcount' ]} " ,
1040+ f"insertstart={ insert_test_params ['insertstart' ]} " ,
1041+ ]
1042+ else :
1043+ parameters += [f"recordcount={ items } " ]
1044+
1045+ cwd = "YCSB"
1046+ max_arg_strlen = get_max_arg_strlen ()
1047+ if too_long_params := [arg for arg in parameters if len (arg ) > max_arg_strlen ]:
1048+ parameters = [arg for arg in parameters if arg not in too_long_params ]
1049+ logger .info (f"Some parameters are too long to provide via CLI: { too_long_params } " )
1050+ custom_workload = f"{ workload } _custom_{ uuid4 ().hex [:6 ]} "
1051+ logger .info (
1052+ f"Copying { workload } file to { custom_workload } and inserting long parameters there."
1053+ )
1054+ inject_params_into_ycsb_workload_file (
1055+ f"{ cwd } /{ workload } " , f"{ cwd } /{ custom_workload } " , too_long_params
1056+ )
1057+ workload = custom_workload
1058+
1059+ cmd_args = ["bin/ycsb" , action , ycsb_client ]
1060+ if ycsb_status_output :
1061+ cmd_args .append ("-s" )
1062+ cmd_args += ["-threads" , workers , "-P" , workload ] + [
1063+ arg for param in parameters for arg in ["-p" , param ]
1064+ ]
1065+ cmd_args = list (map (str , cmd_args ))
1066+
1067+ logger .info (f"Running: { shlex .join (cmd_args )} " )
1068+ run_local_shell_command ("pyenv local 2.7.18" , quiet = True , cwd = cwd )
1069+ with open (f"{ cwd } /ycsb_{ action } _{ instance } _{ database } _stderr.log" , "w" ) as stderr_file :
1070+ run_local_shell_command (cmd_args , quiet = True , cwd = cwd , stderr = stderr_file )
1071+
1072+
9331073def inject_params_into_ycsb_workload_file (
9341074 source_filename : str , target_filename : str , params : list [str ]
9351075):
0 commit comments