Skip to content

Instantly share code, notes, and snippets.

@devoto13
Created July 30, 2015 10:24
Show Gist options
  • Save devoto13/5ba2d0a8d40c06ab907b to your computer and use it in GitHub Desktop.
Save devoto13/5ba2d0a8d40c06ab907b to your computer and use it in GitHub Desktop.
Modified hatch() method for locust
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