Created
July 30, 2015 10:24
-
-
Save devoto13/5ba2d0a8d40c06ab907b to your computer and use it in GitHub Desktop.
Modified hatch() method for locust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hatch(): | |
sleep_time = 1.0 / self.hatch_rate | |
while True: | |
if not bucket: | |
if sum(occurrence_count.values()) < spawn_count: | |
gevent.sleep(0.5) | |
continue | |
else: | |
logger.info("All locusts hatched: %s" % ", ".join( | |
["%s: %d" % (name, count) for name, count in occurrence_count.iteritems()])) | |
events.hatch_complete.fire(user_count=self.num_clients) | |
return | |
locust = bucket.pop(random.randint(0, len(bucket) - 1)) | |
def start_locust(_): | |
try: | |
l = locust() | |
occurrence_count[locust.__name__] += 1 | |
l.run() | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment