Skip to content

Commit

Permalink
Merge pull request locustio#13 from cpennington/reconfigure-signal
Browse files Browse the repository at this point in the history
Add event for allowing plugins to handle reconfiguration events trigg…
  • Loading branch information
cpennington committed Aug 27, 2015
2 parents 9d62326 + 7ea9bee commit 588d9b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions locust/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ def fire(self, **kwargs):
"""
*locust_stop_hatching* is fired when terminate the hatching process on any locust worker.
"""

reconfigure = EventHook()
"""
*reconfigure* is fired when configuration is changed. On slaves, it is also called
when configuration is sent from the master.
"""
18 changes: 17 additions & 1 deletion locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random
import logging
from time import time
from datetime import datetime
from hashlib import md5

import gevent
Expand Down Expand Up @@ -37,6 +38,10 @@ def __init__(self, locust_classes, options):
self.hatching_greenlet = None
self.exceptions = {}
self.stats = global_stats
self.testid = datetime.now().isoformat()
self.precision = options.precision

self.sync_configuration()

# register listener that resets stats when hatching is complete
def on_hatch_complete(user_count):
Expand Down Expand Up @@ -187,6 +192,12 @@ def log_exception(self, node_id, msg, formatted_tb):
row["nodes"].add(node_id)
self.exceptions[key] = row

def sync_configuration(self):
events.reconfigure.fire(
precision=self.precision,
testid=self.testid,
)

class LocalLocustRunner(LocustRunner):
def __init__(self, locust_classes, options):
super(LocalLocustRunner, self).__init__(locust_classes, options)
Expand Down Expand Up @@ -287,7 +298,8 @@ def start_hatching(self, locust_count, hatch_rate):
"num_clients":slave_num_clients,
"num_requests": self.num_requests,
"host":self.host,
"stop_timeout":None
"stop_timeout":None,
"testid":self.testid,
}

if remaining > 0:
Expand Down Expand Up @@ -388,6 +400,10 @@ def worker(self):
#self.num_clients = job["num_clients"]
self.num_requests = job["num_requests"]
self.host = job["host"]
self.testid = job["testid"]

self.sync_configuration()

self.hatching_greenlet = gevent.spawn(lambda: self.start_hatching(locust_count=job["num_clients"], hatch_rate=job["hatch_rate"]))
elif msg.type == "stop":
self.stop()
Expand Down

0 comments on commit 588d9b0

Please sign in to comment.