Locust: Tasks running, no stats collected.

Created on 26 Jun 2015  路  7Comments  路  Source: locustio/locust

I installed locust with pip, used this example:

from locust import Locust, TaskSet, task

class MyTaskSet(TaskSet):
@task
def my_task(self):
print "executing my_task"

class MyLocust(Locust):
task_set = MyTaskSet
min_wait = 5000
max_wait = 15000

run it with:

locust -f locus_test.py

I'm seeing tasks logging:

[2015-06-26 18:08:05,921] krzysztofs-MacBook-Pro.local/INFO/stdout:
[2015-06-26 18:08:05,922] krzysztofs-MacBook-Pro.local/INFO/stdout: executing my_task
[2015-06-26 18:08:05,923] krzysztofs-MacBook-Pro.local/INFO/stdout:
[2015-06-26 18:08:05,925] krzysztofs-MacBook-Pro.local/INFO/stdout: executing my_task
[2015-06-26 18:08:05,925] krzysztofs-MacBook-Pro.local/INFO/stdout:
[2015-06-26 18:08:05,928] krzysztofs-MacBook-Pro.local/INFO/stdout: executing my_task
[2015-06-26 18:08:05,928] krzysztofs-MacBook-Pro.local/INFO/stdout:

Locust web shows no stats.

this url: http://localhost:8089/stats/requests returns:

{"errors": [], "stats": [{"median_response_time": null, "min_response_time": 0, "current_rps": 0, "name": "Total", "num_failures": 0, "max_response_time": 0, "avg_content_length": 0, "avg_response_time": 0, "method": null, "num_requests": 0}], "state": "hatching", "total_rps": 0, "fail_ratio": 0.0, "user_count": 2}

Most helpful comment

I figured out the issue, it has to do with catch_response=True, i removed it and its working. I used it without understanding what it does :(

All 7 comments

What stats would there be if you weren't calling out to anything? This is expected.

I have a custom API that I need to test - is there a way I could capture stats for @task?

My usecase:

@task
def my_task(self):
api = SomeApi("initializing custom api")
api.authenticate('user', 'pass')
api.execute_some_method()

class MyLocust(Locust):
task_set = MyTaskSet
min_wait = 5000
max_wait = 15000

execute_some_method actually talks to a backend service, but I don't know how to capture stats for this.

@krzysztofszymanski have you taken a look at http://docs.locust.io/en/latest/testing-other-systems.html? You'll just need to trigger the locust.request_success and locust.request_failure events after calling your API.

I just started using locust and I am having a very similar issue. Not sure if I am doing something wrong. I am not seeing any stats. All the examples I have seen show that there are stats displayed on the web ui with very similar setup. I have printed out responses locally and I see successful outputs and the status codes are appropriate (2xx for successes and 4xx for failures)

locust version: 0.7.3
os: mac os x - yosemite

Locustfile:

from locust import HttpLocust, TaskSet, task
import json
import random

class SignupBehavior(TaskSet):
def on_start(self):
self.signup()

def signup(self):
    email = "performance{0}@test.com".format(random.randint(1,9999))
    payload = { "email":email, "password":"stark"}
    headers = {'content-type': 'application/json'}
    response = self.client.post("/signup", data=json.dumps(payload) , headers=headers, catch_response=True)
    jsonResponse = json.loads(response.content)
    self.token = jsonResponse['token']

@task
def updateUser(self):
    headers = {'content-type': 'application/json' , 'authorization':self.token}
    payload = {"firstName":"Arya", "lastName":"Stark" }
    self.client.put("/users", data=json.dumps(payload) , headers=headers, catch_response=True)

@task
def getUser(self):
    headers = {'content-type': 'application/json', 'Authorization':self.token }
    self.client.get("/users", headers=headers, catch_response=True)

class ServiceUser(HttpLocust):
    task_set = SignupBehavior
    min_wait=5000
    max_wait=9000

I figured out the issue, it has to do with catch_response=True, i removed it and its working. I used it without understanding what it does :(

@shyamvala Thank you, I did exactly the same thing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

styk-tv picture styk-tv  路  3Comments

max-rocket-internet picture max-rocket-internet  路  3Comments

bretrouse picture bretrouse  路  4Comments

YannickXiong picture YannickXiong  路  3Comments