Skip to content

Commit

Permalink
set correct VU count for locust (Blazemeter#1391)
Browse files Browse the repository at this point in the history
write 'allThreads' field in .jtl file
  • Loading branch information
Merilian authored Sep 24, 2020
1 parent f0388a4 commit d96496f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bzt/resources/locustio-taurus-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
super(LocustStarter, self).__init__()
self.fhd = None
self.writer = None
self.runner = None
self.locust_start_time = None
self.locust_stop_time = None

Expand All @@ -42,8 +43,7 @@ def __check_limits(self):
if self.num_requests <= 0:
raise StopUser('Request limit reached')

@staticmethod
def __getrec(request_type, name, response_time, response_length, exc=None):
def __getrec(self, request_type, name, response_time, response_length, exc=None):
rcode = '200' if exc is None else '500'
rmsg = 'OK' if exc is None else '%s' % exc
if isinstance(exc, HTTPError):
Expand All @@ -54,6 +54,7 @@ def __getrec(request_type, name, response_time, response_length, exc=None):
response_time = int(round(response_time))

return OrderedDict([
('allThreads', self.runner.user_count if self.runner else 0),
('timeStamp', "%d" % (time.time() * 1000)),
('label', name),
('method', request_type),
Expand All @@ -64,10 +65,13 @@ def __getrec(request_type, name, response_time, response_length, exc=None):
('success', 'true' if exc is None else 'false'),

# NOTE: might be resource-consuming
('allThreads', 0),
('Latency', 0),
])

def __on_init(self, **args):
if 'runner' in args:
self.runner = args['runner']

def __on_request_success(self, request_type, name, response_time, response_length):
self.num_requests -= 1
self.writer.writerow(self.__getrec(request_type, name, response_time, response_length))
Expand All @@ -94,7 +98,7 @@ def __on_worker_report(self, client_id, data):
self.fhd.flush()
self.__check_limits()

def __on_quit(self):
def __on_quit(self, **args):
self.locust_stop_time = time.time()

def execute(self):
Expand All @@ -117,6 +121,7 @@ def execute(self):
else:
self.writer = None # FIXME: bad code design, have zero object for it

events.init.add_listener(self.__on_init)
events.request_success.add_listener(self.__on_request_success)
events.request_failure.add_listener(self.__on_request_failure)
events.user_error.add_listener(self.__on_exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set correct value to 'allThreads' field in .jtl file in locust

0 comments on commit d96496f

Please sign in to comment.