Example #1
0
    def start_hatching(self, locust_count, hatch_rate):
        self.num_clients = locust_count
        slave_num_clients = locust_count / ((len(self.clients.ready) + len(self.clients.running)) or 1)
        slave_hatch_rate = float(hatch_rate) / ((len(self.clients.ready) + len(self.clients.running)) or 1)

        logger.info("Sending hatch jobs to %i ready clients" % (len(self.clients.ready) + len(self.clients.running)))
        if not (len(self.clients.ready) + len(self.clients.running)):
            logger.warning(
                "You are running in distributed mode but have no slave servers connected. Please connect slaves prior to swarming."
            )
            return

        if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
            RequestStats.clear_all()

        for client in self.clients.itervalues():
            data = {
                "hatch_rate": slave_hatch_rate,
                "num_clients": slave_num_clients,
                "num_requests": self.num_requests,
                "host": self.host,
                "stop_timeout": None,
            }
            self.server.send(Message("hatch", data, None))

        RequestStats.global_start_time = time()
        self.state = STATE_HATCHING
Example #2
0
    def start_hatching(self, locust_count, hatch_rate):
        self.num_clients = locust_count
        slave_num_clients = locust_count / (
            (len(self.clients.ready) + len(self.clients.running)) or 1)
        slave_hatch_rate = float(hatch_rate) / (
            (len(self.clients.ready) + len(self.clients.running)) or 1)

        logger.info("Sending hatch jobs to %i ready clients" %
                    (len(self.clients.ready) + len(self.clients.running)))
        if not (len(self.clients.ready) + len(self.clients.running)):
            logger.warning(
                "You are running in distributed mode but have no slave servers connected. Please connect slaves prior to swarming."
            )
            return

        if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
            RequestStats.clear_all()

        for client in self.clients.itervalues():
            msg = {
                "hatch_rate": slave_hatch_rate,
                "num_clients": slave_num_clients,
                "num_requests": self.num_requests,
                "host": self.host,
                "stop_timeout": None
            }
            self.server.send({"type": "hatch", "data": msg})

        RequestStats.global_start_time = time()
        self.state = STATE_HATCHING
Example #3
0
    def start_hatching(self, locust_count=None, hatch_rate=None, wait=False):
        if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
            RequestStats.clear_all()
            RequestStats.global_start_time = time()
            self.exceptions = {}

        # Dynamically changing the locust count
        if self.state != STATE_INIT and self.state != STATE_STOPPED:
            self.state = STATE_HATCHING
            if self.num_clients > locust_count:
                # Kill some locusts
                kill_count = self.num_clients - locust_count
                self.kill_locusts(kill_count)
            elif self.num_clients < locust_count:
                # Spawn some locusts
                if hatch_rate:
                    self.hatch_rate = hatch_rate
                spawn_count = locust_count - self.num_clients
                self.spawn_locusts(spawn_count=spawn_count)
        else:
            if hatch_rate:
                self.hatch_rate = hatch_rate
            if locust_count:
                self.spawn_locusts(locust_count, wait=wait)
            else:
                self.spawn_locusts(wait=wait)
Example #4
0
    def start_hatching(self, locust_count=None, hatch_rate=None, wait=False):
        if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
            RequestStats.clear_all()
            RequestStats.global_start_time = time()
            self.exceptions = {}

        # Dynamically changing the locust count
        if self.state != STATE_INIT and self.state != STATE_STOPPED:
            self.state = STATE_HATCHING
            if self.num_clients > locust_count:
                # Kill some locusts
                kill_count = self.num_clients - locust_count
                self.kill_locusts(kill_count)
            elif self.num_clients < locust_count:
                # Spawn some locusts
                if hatch_rate:
                    self.hatch_rate = hatch_rate
                spawn_count = locust_count - self.num_clients
                self.spawn_locusts(spawn_count=spawn_count)
        else:
            if hatch_rate:
                self.hatch_rate = hatch_rate
            if locust_count:
                self.spawn_locusts(locust_count, wait=wait)
            else:
                self.spawn_locusts(wait=wait)
Example #5
0
    def ramp_down(clients, hatch_stride):
        while True:
            if locust_runner.state != STATE_HATCHING:
                if locust_runner.num_clients < max_locusts:
                    gevent.sleep(calibration_time)
                    fail_ratio = RequestStats.sum_stats().fail_ratio
                    if fail_ratio <= acceptable_fail:
                        p = current_percentile(percent)
                        if p <= response_time_limit:
                            if hatch_stride <= precision:
                                logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients))
                                return remove_listeners()

                            logger.info("Ramping up...")
                            hatch_stride = max((hatch_stride/2),precision)
                            clients += hatch_stride
                            locust_runner.start_hatching(clients, locust_runner.hatch_rate)
                            return ramp_up(clients, hatch_stride, True)

                logger.info("Ramping down...")
                hatch_stride = max((hatch_stride/2),precision)
                clients -= hatch_stride
                if clients > 0:
                    locust_runner.start_hatching(clients, locust_runner.hatch_rate)
                else:
                    logger.warning("No responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address")
                    logger.info("RAMING STOPPED")
                    return remove_listeners()
            gevent.sleep(1)
Example #6
0
    def ramp_up(clients, hatch_stride, boundery_found=False):
        while True:
            if locust_runner.state != STATE_HATCHING:
                if locust_runner.num_clients >= max_locusts:
                    logger.info("Ramp up halted; Max locusts limit reached: %d" % max_locusts)
                    return ramp_down(clients, hatch_stride)

                gevent.sleep(calibration_time)
                fail_ratio = RequestStats.sum_stats().fail_ratio
                if fail_ratio > acceptable_fail:
                    logger.info("Ramp up halted; Acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100))
                    return ramp_down(clients, hatch_stride)

                p = current_percentile(percent)
                if p >= response_time_limit:
                    logger.info("Ramp up halted; Percentile response times getting high: %d" % p)
                    return ramp_down(clients, hatch_stride)

                if boundery_found and hatch_stride <= precision:
                    logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients))
                    return remove_listeners()

                logger.info("Ramping up...")
                if boundery_found:
                    hatch_stride = max((hatch_stride/2),precision)
                clients += hatch_stride
                locust_runner.start_hatching(clients, locust_runner.hatch_rate)
            gevent.sleep(1)
Example #7
0
    def ramp_down(clients, hatch_stride):
        while True:
            if locust_runner.state != STATE_HATCHING:
                if locust_runner.num_clients < max_locusts:
                    gevent.sleep(calibration_time)
                    fail_ratio = RequestStats.sum_stats().fail_ratio
                    if fail_ratio <= acceptable_fail:
                        p = current_percentile(percent)
                        if p <= response_time_limit:
                            if hatch_stride <= precision:
                                logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients))
                                return remove_listeners()

                            logger.info("Ramping up...")
                            hatch_stride = max((hatch_stride/2),precision)
                            clients += hatch_stride
                            locust_runner.start_hatching(clients, locust_runner.hatch_rate)
                            return ramp_up(clients, hatch_stride, True)

                logger.info("Ramping down...")
                hatch_stride = max((hatch_stride/2),precision)
                clients -= hatch_stride
                if clients > 0:
                    locust_runner.start_hatching(clients, locust_runner.hatch_rate)
                else:
                    logger.warning("No responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address")
                    logger.info("RAMING STOPPED")
                    return remove_listeners()
            gevent.sleep(1)
Example #8
0
    def ramp_up(clients, hatch_stride, boundery_found=False):
        while True:
            if locust_runner.state != STATE_HATCHING:
                if locust_runner.num_clients >= max_locusts:
                    logger.info("Ramp up halted; Max locusts limit reached: %d" % max_locusts)
                    return ramp_down(clients, hatch_stride)

                gevent.sleep(calibration_time)
                fail_ratio = RequestStats.sum_stats().fail_ratio
                if fail_ratio > acceptable_fail:
                    logger.info("Ramp up halted; Acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100))
                    return ramp_down(clients, hatch_stride)

                p = current_percentile(percent)
                if p >= response_time_limit:
                    logger.info("Ramp up halted; Percentile response times getting high: %d" % p)
                    return ramp_down(clients, hatch_stride)

                if boundery_found and hatch_stride <= precision:
                    logger.info("Sweet spot found! Ramping stopped at %i locusts" % (locust_runner.num_clients))
                    return remove_listeners()

                logger.info("Ramping up...")
                if boundery_found:
                    hatch_stride = max((hatch_stride/2),precision)
                clients += hatch_stride
                locust_runner.start_hatching(clients, locust_runner.hatch_rate)
            gevent.sleep(1)
Example #9
0
 def ramp_up(clients, hatch_stride, boundery_found=False):
     while True:
         if self.state != STATE_HATCHING:
             if self.num_clients >= max_locusts:
                 print "ramp up stopped due to max locusts limit reached:", max_locusts
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             gevent.sleep(calibration_time)
             fail_ratio = RequestStats.sum_stats().fail_ratio
             if fail_ratio > acceptable_fail:
                 print "ramp up stopped due to acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100)
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             p = current_percentile(percent)
             if p >= response_time_limit:
                 print "ramp up stopped due to percentile response times getting high:", p
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             if boundery_found and hatch_stride <= precision:
                 print "sweet spot found, ramping stopped!"
                 return
             print "ramping up..."
             if boundery_found:
                 hatch_stride = max((hatch_stride/2),precision)
             clients += hatch_stride
             self.start_hatching(clients, self.hatch_rate)
         gevent.sleep(1)
Example #10
0
 def stats_csv(self):
     rows = [
         ",".join([
             '"Method"',
             '"Name"',
             '"# requests"',
             '"# failures"',
             '"Median response time"',
             '"Average response time"',
             '"Min response time"', 
             '"Max response time"',
             '"Average Content Size"',
             '"Reqests/s"',
         ])
     ]
 
     for s in chain(_sort_stats(self.request_stats), [RequestStats.sum_stats("Total", full_request_history=True)]):
         rows.append('"%s","%s",%i,%i,%i,%i,%i,%i,%i,%.2f' % (
             s.method,
             s.name,
             s.num_reqs,
             s.num_failures,
             s.median_response_time,
             s.avg_response_time,
             s.min_response_time or 0,
             s.max_response_time,
             s.avg_content_length,
             s.total_rps,
         ))
 
     return "\n".join(rows)
Example #11
0
File: core.py Project: d1on/locust
 def ramp_up(clients, hatch_stride, boundery_found=False):
     while True:
         if self.state != STATE_HATCHING:
             if self.num_clients >= max_locusts:
                 print "ramp up stopped due to max locusts limit reached:", max_locusts
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             gevent.sleep(calibration_time)
             fail_ratio = RequestStats.sum_stats().fail_ratio
             if fail_ratio > acceptable_fail:
                 print "ramp up stopped due to acceptable fail ratio %d%% exceeded with fail ratio %d%%" % (acceptable_fail*100, fail_ratio*100)
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             p = current_percentile(percent)
             if p >= response_time_limit:
                 print "ramp up stopped due to percentile response times getting high:", p
                 client, hatch_stride = ramp_down_help(clients, hatch_stride)
                 return ramp_down(clients, hatch_stride)
             if boundery_found and hatch_stride <= precision:
                 print "sweet spot found, ramping stopped!"
                 return
             print "ramping up..."
             if boundery_found:
                 hatch_stride = max((hatch_stride/2),precision)
             clients += hatch_stride
             self.start_hatching(clients, self.hatch_rate)
         gevent.sleep(1)
Example #12
0
File: core.py Project: d1on/locust
 def ramp_down(clients, hatch_stride):
     while True:
         if self.state != STATE_HATCHING:
             if self.num_clients < max_locusts:
                 gevent.sleep(calibration_time)
                 fail_ratio = RequestStats.sum_stats().fail_ratio
                 if fail_ratio <= acceptable_fail:
                     p = current_percentile(percent)
                     if p <= response_time_limit:
                         if hatch_stride <= precision:
                             print "sweet spot found, ramping stopped!"
                             return
                         print "ramping up..."
                         hatch_stride = max((hatch_stride/2),precision)
                         clients += hatch_stride
                         self.start_hatching(clients, self.hatch_rate)
                         return ramp_up(clients, hatch_stride, True)
             print "ramping down..."
             hatch_stride = max((hatch_stride/2),precision)
             clients -= hatch_stride
             if clients > 0:
                 self.start_hatching(clients, self.hatch_rate)
             else:
                 print "WARNING: no responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address"
                 print "ramping stopped!"
                 return
         gevent.sleep(1)
Example #13
0
 def ramp_down(clients, hatch_stride):
     while True:
         if self.state != STATE_HATCHING:
             if self.num_clients < max_locusts:
                 gevent.sleep(calibration_time)
                 fail_ratio = RequestStats.sum_stats().fail_ratio
                 if fail_ratio <= acceptable_fail:
                     p = current_percentile(percent)
                     if p <= response_time_limit:
                         if hatch_stride <= precision:
                             print "sweet spot found, ramping stopped!"
                             return
                         print "ramping up..."
                         hatch_stride = max((hatch_stride/2),precision)
                         clients += hatch_stride
                         self.start_hatching(clients, self.hatch_rate)
                         return ramp_up(clients, hatch_stride, True)
             print "ramping down..."
             hatch_stride = max((hatch_stride/2),precision)
             clients -= hatch_stride
             if clients > 0:
                 self.start_hatching(clients, self.hatch_rate)
             else:
                 print "WARNING: no responses met the ramping thresholds, check your ramp configuration, locustfile and \"--host\" address"
                 print "ramping stopped!"
                 return
         gevent.sleep(1)
Example #14
0
File: core.py Project: d1on/locust
    def start_hatching(self, locust_count, hatch_rate):
        self.num_clients = locust_count
        slave_num_clients = locust_count / ((len(self.clients.ready) + len(self.clients.running)) or 1)
        slave_hatch_rate = float(hatch_rate) / ((len(self.clients.ready) + len(self.clients.running)) or 1)

        print "Sending hatch jobs to %i ready clients" % (len(self.clients.ready) + len(self.clients.running))
        if not (len(self.clients.ready)+len(self.clients.running)):
            print "WARNING: You are running in distributed mode but have no slave servers connected."
            print "Please connect slaves prior to swarming."
        
        if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
            RequestStats.clear_all()
        
        for client in self.clients.itervalues():
            msg = {"hatch_rate":slave_hatch_rate, "num_clients":slave_num_clients, "num_requests": self.num_requests, "host":self.host, "stop_timeout":None}
            self.server.send({"type":"hatch", "data":msg})
        
        RequestStats.global_start_time = time()
        self.state = STATE_HATCHING
Example #15
0
def on_request_success_ramping(_, _1, response_time, _2):
    if is_distributed:
        response_times.append(response_time)
    else:
        response_times.append(response_time)

        # remove from the queue
        rps = RequestStats.sum_stats().current_rps
        if len(response_times) > rps*PERCENTILE_TIME_WINDOW:
            for i in xrange(len(response_times) - int(math.ceil(rps*PERCENTILE_TIME_WINDOW))):
                response_times.popleft()
Example #16
0
def on_request_success_ramping(_, _1, response_time, _2):
    if is_distributed:
        response_times.append(response_time)
    else:
        response_times.append(response_time)

        # remove from the queue
        rps = RequestStats.sum_stats().current_rps
        if len(response_times) > rps*PERCENTILE_TIME_WINDOW:
            for i in xrange(len(response_times) - int(math.ceil(rps*PERCENTILE_TIME_WINDOW))):
                response_times.popleft()
Example #17
0
 def distribution_stats_csv(self):
     rows = [",".join((
         '"Name"',
         '"# requests"',
         '"50%"',
         '"66%"',
         '"75%"',
         '"80%"',
         '"90%"',
         '"95%"',
         '"98%"',
         '"99%"',
         '"100%"',
     ))]
     for s in chain(_sort_stats(self.request_stats), [RequestStats.sum_stats("Total", full_request_history=True)]):
         if s.num_reqs:
             rows.append(s.percentile(tpl='"%s",%i,%i,%i,%i,%i,%i,%i,%i,%i,%i'))
         else:
             rows.append('"%s",0,"N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"' % s.name)        
     return "\n".join(rows)
Example #18
0
 def on_hatch_complete(count):
     self.state = STATE_RUNNING
     logger.info("Resetting stats\n")
     RequestStats.reset_all()
Example #19
0
File: core.py Project: d1on/locust
 def on_hatch_complete(count):
     self.state = STATE_RUNNING
     print "Resetting stats\n"
     RequestStats.reset_all()
Example #20
0
 def on_hatch_complete(count):
     self.state = STATE_RUNNING
     logger.info("Resetting stats\n")
     RequestStats.reset_all()