Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks running, no stats collected. #301

Closed
krzysztofszymanski opened this issue Jun 26, 2015 · 8 comments
Closed

Tasks running, no stats collected. #301

krzysztofszymanski opened this issue Jun 26, 2015 · 8 comments

Comments

@krzysztofszymanski
Copy link

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}

@RollForReflex
Copy link

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

@krzysztofszymanski
Copy link
Author

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

@krzysztofszymanski
Copy link
Author

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.

@carlosvargas
Copy link

@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.

@shyamvala
Copy link

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

@shyamvala
Copy link

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 :(

@EvilCreamsicle
Copy link

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

@ruchikakhemka2021
Copy link

@shyamvala Thank you, I removed the catch_response=True and stats started popping up on the UI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants