Skip to content

Commit

Permalink
added basic support for multiple locusts
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Hamren authored and heyman committed Feb 18, 2011
1 parent 6162bcb commit b6103d8
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 275 deletions.
30 changes: 22 additions & 8 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class User(Locust):

stop_timeout = None
"""Number of seconds after which the Locust will die. If None it won't timeout."""


weight = 10
"""Weight"""

__metaclass__ = LocustMeta

def __init__(self):
Expand Down Expand Up @@ -153,20 +156,31 @@ def __init__(self):
locusts = []
locust_runner = None

def hatch(locust, hatch_rate, num_clients, host=None, stop_timeout=None):
if host is not None:
locust.host = host
if stop_timeout is not None:
locust.stop_timeout = stop_timeout

def hatch(locust_list, hatch_rate, num_clients, host=None, stop_timeout=None):
pool = []
for locust in locust_list:
if host is not None:
locust.host = host
if stop_timeout is not None:
locust.stop_timeout = stop_timeout

for x in xrange(0, locust.weight):
pool.append(locust)

print pool

print "Hatching and swarming %i clients at the rate %i clients/s..." % (num_clients, hatch_rate)
while True:
for i in range(0, hatch_rate):
if len(locusts) >= num_clients:
print "All locusts hatched"
gevent.joinall(locusts)
return
new_locust = gevent.spawn(locust())

random_locust = random.choice(pool)()
print random_locust

new_locust = gevent.spawn(random_locust)
new_locust.link(on_death)
locusts.append(new_locust)
print "%i locusts hatched" % (len(locusts))
Expand Down
Loading

0 comments on commit b6103d8

Please sign in to comment.