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

Negative min_response_time shown in stats #1487

Closed
max-rocket-internet opened this issue Jul 22, 2020 · 9 comments · Fixed by #1492
Closed

Negative min_response_time shown in stats #1487

max-rocket-internet opened this issue Jul 22, 2020 · 9 comments · Fixed by #1492
Labels

Comments

@max-rocket-internet
Copy link
Contributor

Describe the bug

Negative value shown for min_response_time:

Screen Shot 2020-07-22 at 17 58 54

Expected behavior

0 or positive value.

Actual behavior

Negative value shown for min_response_time

Steps to reproduce

I have a branch local docker-compose setup to reproduce it easily. But it's just 1 worker calling nginx in another docker container.

Environment

  • OS: Docker
  • Python version: -
  • Locust version: current master
@max-rocket-internet
Copy link
Contributor Author

max-rocket-internet commented Jul 22, 2020

This line is returning a negative value:

request_meta["response_time"] = (time.time() - request_meta["start_time"]) * 1000

Perhaps a docker clock source issue 🤔

Docker itself just using the host clock source but docker on Mac (what I'm using) uses HyperKit VM as Mac kernel doesn't support native docker. Perhaps this VM clock source is not reliable?

@max-rocket-internet
Copy link
Contributor Author

There's lots of docker clock issues but as far as I can see they are related to sleep: moby/hyperkit#110

If it was a docker issue, it would be easy to reproduce outside of locust with a file like this:

import time

while True:
    t = time.time()
    if time.time() < t:
        print('ERROR: {0} is less than {1}'.format(time.time(), t))
        break

And then run it like docker run -v $PWD:/mnt python:latest python /mnt/time_test.py

@max-rocket-internet
Copy link
Contributor Author

Ah, after leaving this for a while I get an error 😅

ERROR: 1595435189.4236984 is less than 1595435189.4583442

OK, good to know!

@max-rocket-internet
Copy link
Contributor Author

Should we make a change to the locust code though? Like to record the response time as 0 in this case?

@cyberw
Copy link
Collaborator

cyberw commented Jul 22, 2020

Can you try replacing the two calls to time.time() with time.monotonic()?

I thought we did that a long time ago, but maybe it was only done for FastHttpUser or something.

@heyman
Copy link
Member

heyman commented Jul 22, 2020

Interesting.

Should we make a change to the locust code though? Like to record the response time as 0 in this case?

I don't think we should "hide" the clock issue by setting it to zero if it's negative.

@max-rocket-internet
Copy link
Contributor Author

I don't think we should "hide" the clock issue by setting it to zero if it's negative.

Makes sense

Can you try replacing the two calls to time.time() with time.monotonic()?

This solves it for me. Both in docker without locust and in my locust test.

Shall I make a PR to switch any time measurement to use time.monotonic()? We should probably be using this anyway as even without docker the main clock on any host can go backwards (with NTP, chrony etc) anyway

@cyberw
Copy link
Collaborator

cyberw commented Jul 23, 2020

Please do!

@max-rocket-internet
Copy link
Contributor Author

Done: #1492

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

Successfully merging a pull request may close this issue.

3 participants