def shutdown(): """ Shut down locust by firing quitting event, printing/writing stats and exiting """ logger.info("Running teardowns...") environment.events.quitting.fire(environment=environment, reverse=True) # determine the process exit code if log.unhandled_greenlet_exception: code = 2 elif environment.process_exit_code is not None: code = environment.process_exit_code elif len(runner.errors) or len(runner.exceptions): code = options.exit_code_on_error else: code = 0 logger.info("Shutting down (exit code %s), bye." % code) if stats_printer_greenlet is not None: stats_printer_greenlet.kill(block=False) logger.info("Cleaning up runner...") if runner is not None: runner.quit() print_stats(runner.stats, current=False) print_percentile_stats(runner.stats) print_error_report(runner.stats) sys.exit(code)
def shutdown(self, code=0): """ Shut down locust by firing quitting event, printing stats and exiting """ logger.debug("######## DEBUG: shutdown()/_locustrunner = {}".format(self._locustrunner)) logger.info("##### Locust plugin: Cleaning up runner...") if self._locustrunner is not None and self.is_any_slave_up(): #if self.csvfilebase: # write_stat_csvs(self.csvfilebase) retcode = self._locustrunner.quit() logger.debug("######## DEBUG: shutdown()/_locustrunner.quit() passed # retcode = {}".format(retcode)) logger.info("##### Locust plugin: Running teardowns...") while not self.reader.is_stat_queue_empty(): logger.info("##### Locust plugin: {} items remaining is stats queue".format(self.reader.stat_queue.qsize())) time.sleep(1) ### FIXME : possibly causing a greenlet looping infinitely #events.quitting.fire(reverse=True) print_stats(self._locustrunner.request_stats) print_percentile_stats(self._locustrunner.request_stats) print_error_report() self.reader.close() logger.info("##### Locust plugin: Shutting down (exit code %s), bye." % code)
def start_master(locust_classes, slaves_num): # web # logger.info("Starting web monitor at {}:{}".format( # master_options.web_host or "*", master_options.port)) # master_greenlet = gevent.spawn(web.start, locust_classes, master_options) # no_web # todo: run time runners.locust_runner = runners.MasterLocustRunner(locust_classes, master_options) while len(runners.locust_runner.clients.ready) < slaves_num: logger.info("Waiting for slaves to be ready, %s of %s connected", len(runners.locust_runner.clients.ready), slaves_num) time.sleep(1) logger.info("%s slave connected, start hatching", len(runners.locust_runner.clients.ready)) runners.locust_runner.start_hatching(master_options.num_clients, master_options.hatch_rate) master_greenlet = runners.locust_runner.greenlet try: master_greenlet.join() except KeyboardInterrupt: events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) print_error_report() sys.exit(0)
def shutdown(code=0): """ Shut down locust by firing quitting event, printing stats and exiting """ events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) print_error_report() sys.exit(code)
def shutdown(code=0): """ Shut down locust by firing quitting event, printing stats and exiting """ logger.info("Shutting down (exit code %s), bye." % code) events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) print_error_report() sys.exit(code)
def shutdown(options, code=0): """ Shut down locust by firing quitting event, printing/writing stats and exiting """ if runners.locust_runner is not None: runners.locust_runner.stop() events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) if options.csvfilebase: write_stat_csvs(options.csvfilebase) print_error_report()
def start_master(locust_classes): logger.info("Starting web monitor at {}:{}".format( master_options.web_host or "*", master_options.port)) master_greenlet = gevent.spawn(web.start, locust_classes, master_options) runners.locust_runner = runners.MasterLocustRunner(locust_classes, master_options) try: master_greenlet.join() except KeyboardInterrupt: events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) print_error_report() sys.exit(0)
def locust_executor(host, port, collection_name, connection_type="single", run_params=None): m = MilvusClient(host=host, port=port, collection_name=collection_name) MyUser.tasks = {} MyUser.op_info = run_params["op_info"] MyUser.params = {} tasks = run_params["tasks"] for op, value in tasks.items(): task = {eval("Tasks." + op): value["weight"]} MyUser.tasks.update(task) MyUser.params[op] = value["params"] if "params" in value else None logger.info(MyUser.tasks) MyUser.tasks = {Tasks.load: 1, Tasks.flush: 1} MyUser.client = MilvusTask(host=host, port=port, collection_name=collection_name, connection_type=connection_type, m=m) # MyUser.info = m.get_info(collection_name) env = Environment(events=events, user_classes=[MyUser]) runner = env.create_local_runner() # setup logging # setup_logging("WARNING", "/dev/null") # greenlet_exception_logger(logger=logger) gevent.spawn(stats_printer(env.stats)) # env.create_web_ui("127.0.0.1", 8089) # gevent.spawn(stats_printer(env.stats), env, "test", full_history=True) # events.init.fire(environment=env, runner=runner) clients_num = run_params["clients_num"] spawn_rate = run_params["spawn_rate"] during_time = run_params["during_time"] runner.start(clients_num, spawn_rate=spawn_rate) gevent.spawn_later(during_time, lambda: runner.quit()) runner.greenlet.join() print_stats(env.stats) result = { "rps": round(env.stats.total.current_rps, 1), "fail_ratio": env.stats.total.fail_ratio, "max_response_time": round(env.stats.total.max_response_time, 1), "avg_response_time": round(env.stats.total.avg_response_time, 1) } runner.stop() return result
def test_success(request_type, name, response_time, response_length): print('{:5} {:5d} bytes in {:5d} ms from {}'.format( request_type, response_length, response_time, name)) print(str(stats.global_stats.num_requests)) print( stats.global_stats.aggregated_stats().get_response_time_percentile( 95)) print(stats.print_stats(stats.global_stats.entries))
def shutdown(code=0): """ Shut down locust by firing quitting event, printing/writing stats and exiting """ logger.info("Shutting down (exit code %s), bye." % code) if stats_printer_greenlet is not None: stats_printer_greenlet.kill(block=False) logger.info("Cleaning up runner...") if runners.locust_runner is not None: runners.locust_runner.quit() logger.info("Running teardowns...") events.quitting.fire(reverse=True) print_stats(runners.locust_runner.stats, current=False) print_percentile_stats(runners.locust_runner.stats) if options.csvfilebase: write_stat_csvs(options.csvfilebase, options.stats_history_enabled) print_error_report() sys.exit(code)
def test_failure(request_type, name, response_time, exception): # print('\033[41;0;31m{:5} ERROR in {:5d} ms from {} - {}\033[0m'.format(request_type, response_time, name, exception)) print('{:5} !! ERROR !! in {:5d} ms from {} - {}'.format( request_type, response_time, name, exception)) print(str(stats.global_stats.num_requests)) print( stats.global_stats.aggregated_stats().get_response_time_percentile( 95)) print(stats.print_stats(stats.global_stats.entries))
def locust_executor(host, port, collection_name, connection_type="single", run_params=None): m = MilvusClient(host=host, port=port, collection_name=collection_name) MyUser.tasks = {} MyUser.op_info = run_params["op_info"] MyUser.params = {} tasks = run_params["tasks"] for op, value in tasks.items(): task = {eval("Tasks." + op): value["weight"]} MyUser.tasks.update(task) MyUser.params[op] = value["params"] if "params" in value else None logger.info(MyUser.tasks) MyUser.values = { "ids": [random.randint(1000000, 10000000) for _ in range(nb)], "get_ids": [random.randint(1, 10000000) for _ in range(nb)], "X": utils.generate_vectors(nq, MyUser.op_info["dimension"]) } # MyUser.tasks = {Tasks.query: 1, Tasks.flush: 1} MyUser.client = MilvusTask(host=host, port=port, collection_name=collection_name, connection_type=connection_type, m=m) if "load_shape" in run_params and run_params["load_shape"]: test = StepLoadShape() test.init(run_params["step_time"], run_params["step_load"], run_params["spawn_rate"], run_params["during_time"]) env = Environment(events=events, user_classes=[MyUser], shape_class=test) runner = env.create_local_runner() env.runner.start_shape() else: env = Environment(events=events, user_classes=[MyUser]) runner = env.create_local_runner() # setup logging # setup_logging("WARNING", "/dev/null") # greenlet_exception_logger(logger=logger) gevent.spawn(stats_printer(env.stats)) # env.create_web_ui("127.0.0.1", 8089) # gevent.spawn(stats_printer(env.stats), env, "test", full_history=True) # events.init.fire(environment=env, runner=runner) clients_num = run_params[ "clients_num"] if "clients_num" in run_params else 0 step_load = run_params["step_load"] if "step_load" in run_params else 0 step_time = run_params["step_time"] if "step_time" in run_params else 0 spawn_rate = run_params["spawn_rate"] during_time = run_params["during_time"] runner.start(clients_num, spawn_rate=spawn_rate) gevent.spawn_later(during_time, lambda: runner.quit()) runner.greenlet.join() print_stats(env.stats) result = { "rps": round(env.stats.total.current_rps, 1), # Number of interface requests per second "fail_ratio": env.stats.total.fail_ratio, # Interface request failure rate "max_response_time": round(env.stats.total.max_response_time, 1), # Maximum interface response time "avg_response_time": round(env.stats.total.avg_response_time, 1) # ratio of average response time } runner.stop() return result
def main(): parser, options, arguments = parse_options() #print "Options:", options, dir(options) #print "Arguments:", arguments #print "largs:", parser.largs #print "rargs:", parser.rargs # setup logging setup_logging(options.loglevel, options.logfile) logger = logging.getLogger(__name__) if options.show_version: print "Locust %s" % (version) sys.exit(0) locustfile = find_locustfile(options.locustfile) if not locustfile: logger.error("Could not find any locustfile! See --help for available options.") sys.exit(1) docstring, locusts = load_locustfile(locustfile) if options.list_commands: print "Available Locusts:" for name in locusts: print " " + name sys.exit(0) if not locusts: logger.error("No Locust class found!") sys.exit(1) # make sure specified Locust exists if arguments: missing = set(arguments) - set(locusts.keys()) if missing: logger.error("Unknown Locust(s): %s\n" % (", ".join(missing))) sys.exit(1) else: names = set(arguments) & set(locusts.keys()) locust_classes = [locusts[n] for n in names] else: locust_classes = locusts.values() if options.show_task_ratio: print "\n Task ratio per locust class" print "-" * 80 inspectlocust.print_task_ratio(locust_classes) print "\n Total task ratio" print "-" * 80 inspectlocust.print_task_ratio(locust_classes, total=True) sys.exit(0) if options.show_task_ratio_confluence: print "\nh1. Task ratio per locust class" print inspectlocust.print_task_ratio_confluence(locust_classes) print "\nh1. Total task ratio" print inspectlocust.print_task_ratio_confluence(locust_classes, total=True) sys.exit(0) # if --master is set, implicitly set --web if options.master: options.web = True if options.web and not options.slave: # spawn web greenlet logger.info("Starting web monitor on port 8089") main_greenlet = gevent.spawn(web.start, locust_classes, options.hatch_rate, options.num_clients, options.num_requests, options.ramp) # enable/disable gzip in WebLocust's HTTP client WebLocust.gzip = options.gzip if not options.master and not options.slave: core.locust_runner = LocalLocustRunner(locust_classes, options.hatch_rate, options.num_clients, options.num_requests, options.host) # spawn client spawning/hatching greenlet if not options.web: core.locust_runner.start_hatching(wait=True) main_greenlet = core.locust_runner.greenlet elif options.master: core.locust_runner = MasterLocustRunner(locust_classes, options.hatch_rate, options.num_clients, num_requests=options.num_requests, host=options.host, master_host=options.master_host) elif options.slave: core.locust_runner = SlaveLocustRunner(locust_classes, options.hatch_rate, options.num_clients, num_requests=options.num_requests, host=options.host, master_host=options.master_host) main_greenlet = core.locust_runner.greenlet if options.ramp: import rampstats from rampstats import on_request_success, on_report_to_master, on_slave_report import events if options.slave: events.report_to_master += on_report_to_master if options.master: events.slave_report += on_slave_report else: events.request_success += on_request_success if options.print_stats or (not options.web and not options.slave): # spawn stats printing greenlet gevent.spawn(stats_printer) try: logger.info("Starting Locust %s" % version) main_greenlet.join() except KeyboardInterrupt, e: time.sleep(0.2) print_stats(core.locust_runner.request_stats) print_percentile_stats(core.locust_runner.request_stats) print_error_report() logger.info("Got KeyboardInterrupt. Exiting, bye..")