Conditions | 13 |
Total Lines | 98 |
Code Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like milvus_benchmark.main.main() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import os |
||
86 | def main(): |
||
87 | arg_parser = argparse.ArgumentParser( |
||
88 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
||
89 | # helm mode with scheduler |
||
90 | arg_parser.add_argument( |
||
91 | "--image-version", |
||
92 | default="", |
||
93 | help="image version") |
||
94 | arg_parser.add_argument( |
||
95 | "--schedule-conf", |
||
96 | metavar='FILE', |
||
97 | default='', |
||
98 | help="load test schedule from FILE") |
||
99 | arg_parser.add_argument( |
||
100 | "--deploy-mode", |
||
101 | default='', |
||
102 | help="single or shards") |
||
103 | |||
104 | # local mode |
||
105 | arg_parser.add_argument( |
||
106 | '--local', |
||
107 | action='store_true', |
||
108 | help='use local milvus server') |
||
109 | arg_parser.add_argument( |
||
110 | '--host', |
||
111 | help='server host ip param for local mode', |
||
112 | default='127.0.0.1') |
||
113 | arg_parser.add_argument( |
||
114 | '--port', |
||
115 | help='server port param for local mode', |
||
116 | default='19530') |
||
117 | arg_parser.add_argument( |
||
118 | '--suite', |
||
119 | metavar='FILE', |
||
120 | help='load test suite from FILE', |
||
121 | default='') |
||
122 | |||
123 | args = arg_parser.parse_args() |
||
124 | |||
125 | if args.schedule_conf: |
||
126 | if args.local: |
||
127 | raise Exception("Helm mode with scheduler and other mode are incompatible") |
||
128 | if not args.image_version: |
||
129 | raise Exception("Image version not given") |
||
130 | image_version = args.image_version |
||
131 | deploy_mode = args.deploy_mode |
||
132 | with open(args.schedule_conf) as f: |
||
133 | schedule_config = full_load(f) |
||
134 | f.close() |
||
135 | queues = [] |
||
136 | # server_names = set() |
||
137 | server_names = [] |
||
138 | for item in schedule_config: |
||
139 | server_host = item["server"] if "server" in item else "" |
||
140 | suite_params = item["suite_params"] |
||
141 | server_names.append(server_host) |
||
142 | q = Queue() |
||
143 | for suite_param in suite_params: |
||
144 | suite = "suites/"+suite_param["suite"] |
||
145 | image_type = suite_param["image_type"] |
||
146 | image_tag = get_image_tag(image_version, image_type) |
||
147 | q.put({ |
||
148 | "suite": suite, |
||
149 | "server_host": server_host, |
||
150 | "deploy_mode": deploy_mode, |
||
151 | "image_tag": image_tag, |
||
152 | "image_type": image_type |
||
153 | }) |
||
154 | queues.append(q) |
||
155 | logging.error(queues) |
||
156 | thread_num = len(server_names) |
||
157 | processes = [] |
||
158 | |||
159 | for i in range(thread_num): |
||
160 | x = Process(target=queue_worker, args=(queues[i], )) |
||
161 | processes.append(x) |
||
162 | x.start() |
||
163 | time.sleep(10) |
||
164 | for x in processes: |
||
165 | x.join() |
||
166 | |||
167 | elif args.local: |
||
168 | # for local mode |
||
169 | host = args.host |
||
170 | port = args.port |
||
171 | suite = args.suite |
||
172 | with open(suite) as f: |
||
173 | suite_dict = full_load(f) |
||
174 | f.close() |
||
175 | logger.debug(suite_dict) |
||
176 | run_type, run_params = parser.operations_parser(suite_dict) |
||
177 | collections = run_params["collections"] |
||
178 | if len(collections) > 1: |
||
179 | raise Exception("Multi collections not supported in Local Mode") |
||
180 | collection = collections[0] |
||
181 | runner = LocalRunner(host, port) |
||
182 | logger.info("Start run local mode test, test type: %s" % run_type) |
||
183 | runner.run(run_type, collection) |
||
184 | |||
188 |