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 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 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 spawn_locusts(self, spawn_count=None, stop_timeout=None, wait=False): if spawn_count is None: spawn_count = self.num_clients if self.num_requests is not None: RequestStats.global_max_requests = self.num_requests bucket = self.weight_locusts(spawn_count, stop_timeout) spawn_count = len(bucket) if self.state == STATE_INIT or self.state == STATE_STOPPED: self.state = STATE_HATCHING self.num_clients = spawn_count else: self.num_clients += spawn_count logger.info( "Hatching and swarming %i clients at the rate %g clients/s..." % (spawn_count, self.hatch_rate)) occurence_count = dict([(l.__name__, 0) for l in self.locust_classes]) def hatch(): sleep_time = 1.0 / self.hatch_rate while True: if not bucket: logger.info("All locusts hatched: %s" % ", ".join([ "%s: %d" % (name, count) for name, count in occurence_count.iteritems() ])) events.hatch_complete.fire(self.num_clients) return locust = bucket.pop(random.randint(0, len(bucket) - 1)) occurence_count[locust.__name__] += 1 def start_locust(_): try: locust()() except RescheduleTaskImmediately: pass except GreenletExit: pass new_locust = self.locusts.spawn(start_locust, locust) if len(self.locusts) % 10 == 0: logger.debug("%i locusts hatched" % len(self.locusts)) gevent.sleep(sleep_time) hatch() if wait: self.locusts.join() logger.info("All locusts dead\n") print_stats(self.request_stats) print_percentile_stats( self.request_stats ) #TODO use an event listener, or such, for this?
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 spawn_locusts(self, spawn_count=None, stop_timeout=None, wait=False): if spawn_count is None: spawn_count = self.num_clients if self.num_requests is not None: RequestStats.global_max_requests = self.num_requests bucket = self.weight_locusts(spawn_count, stop_timeout) spawn_count = len(bucket) if self.state == STATE_INIT or self.state == STATE_STOPPED: self.state = STATE_HATCHING self.num_clients = spawn_count else: self.num_clients += spawn_count logger.info("Hatching and swarming %i clients at the rate %g clients/s..." % (spawn_count, self.hatch_rate)) occurence_count = dict([(l.__name__, 0) for l in self.locust_classes]) def hatch(): sleep_time = 1.0 / self.hatch_rate while True: if not bucket: logger.info( "All locusts hatched: %s" % ", ".join(["%s: %d" % (name, count) for name, count in occurence_count.iteritems()]) ) events.hatch_complete.fire(self.num_clients) return locust = bucket.pop(random.randint(0, len(bucket) - 1)) occurence_count[locust.__name__] += 1 def start_locust(_): try: locust()() except RescheduleTaskImmediately: pass except GreenletExit: pass new_locust = self.locusts.spawn(start_locust, locust) if len(self.locusts) % 10 == 0: logger.debug("%i locusts hatched" % len(self.locusts)) gevent.sleep(sleep_time) hatch() if wait: self.locusts.join() logger.info("All locusts dead\n") print_stats(self.request_stats) print_percentile_stats(self.request_stats) # TODO use an event listener, or such, for this?
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 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 main(): parser, options, arguments = parse_options() #print "Options:", options, dir(options) #print "Arguments:", arguments #print "largs:", parser.largs #print "rargs:", parser.rargs if options.show_version: print("Locust %s" % (version)) sys.exit(0) locustfile = find_locustfile(options.locustfile) if not locustfile: print "Could not find any locustfile!" 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: sys.stderr.write("No Locust class found!\n") sys.exit(1) # make sure specified Locust exists if arguments: missing = set(arguments) - set(locusts.keys()) if missing: sys.stderr.write("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 print "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: print print "Starting Locust %s" % version print main_greenlet.join() except KeyboardInterrupt, e: time.sleep(0.2) print "\n" print_stats(core.locust_runner.request_stats) print_percentile_stats(core.locust_runner.request_stats) print_error_report() print print "Exiting, bye.." print
def main(): parser, options, arguments = parse_options() #print "Options:", options, dir(options) #print "Arguments:", arguments #print "largs:", parser.largs #print "rargs:", parser.rargs if options.show_version: print("Locust %s" % (version)) sys.exit(0) locustfile = find_locustfile(options.locustfile) if not locustfile: print "Could not find any locustfile!" 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: sys.stderr.write("No Locust class found!\n") sys.exit(1) # make sure specified Locust exists if arguments: missing = set(arguments) - set(locusts.keys()) if missing: sys.stderr.write("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.web and not options.slave: # spawn web greenlet print "Starting web monitor on port 8089" gevent.spawn(web.start, locust_classes, options.hatch_rate, options.num_clients, options.num_requests) 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() elif options.master: core.locust_runner = MasterLocustRunner(locust_classes, options.hatch_rate, options.num_clients, num_requests=options.num_requests, host=options.host, redis_host=options.redis_host, redis_port=options.redis_port) elif options.slave: core.locust_runner = SlaveLocustRunner(locust_classes, options.hatch_rate, options.num_clients, num_requests=options.num_requests, host=options.host, redis_host=options.redis_host, redis_port=options.redis_port) if not options.web or options.print_stats: # spawn stats printing greenlet gevent.spawn(stats_printer) try: print "" print "Starting Locust %s" % version print "" core.locust_runner.greenlet.join() except KeyboardInterrupt, e: print_stats(core.locust_runner.request_stats) print_percentile_stats(core.locust_runner.request_stats) print "" print "Exiting, bye.." print ""
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..")