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

Request time doesn't include download time when use stream #2443

Closed
2 tasks done
zhouweiwei opened this issue Nov 2, 2023 · 5 comments
Closed
2 tasks done

Request time doesn't include download time when use stream #2443

zhouweiwei opened this issue Nov 2, 2023 · 5 comments
Labels
bug invalid stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it

Comments

@zhouweiwei
Copy link

zhouweiwei commented Nov 2, 2023

Prerequisites

Description

I use Locust for performance testing, and one of the cases is downloading files.
However, when using stream=true, the statistics time of Locust does not include the download time of the file.

Command line

locust -f mylocustfile.py --worker --master-host master --host=xxx

Python version

3.8.6

Locust version

2.17

Operating system

mac+docker

Associated issue

#162
067c124

@zhouweiwei zhouweiwei added the bug label Nov 2, 2023
@cyberw
Copy link
Collaborator

cyberw commented Nov 2, 2023

Hi! When using stream=True this is the expected (intentional) behavior. If that is not what you want, you can use catch_response=True and overwrite the response time using something like this:

with self.client.get(..., stream=True, catch_response=True) as resp:
     start_perf_counter = time.perf_counter()
     # download the response
     download_time = (time.perf_counter() - start_perf_counter) * 1000
     resp.request_meta['response_time'] += download_time

@cyberw cyberw added the invalid label Nov 2, 2023
@zhouweiwei
Copy link
Author

zhouweiwei commented Nov 3, 2023

@cyberw
Hello, download is not work when using catch_response=True and stream=True
when catch the response , so you can`t read data from respone .
I get 0 size file after the request .

-rw-r--r-- 1 locust locust    0 Nov  3 02:41 DownloadFile_10102_9202_10014_2473.file
-rw-r--r-- 1 locust locust    0 Nov  3 02:41 DownloadFile_10102_9202_10014_3467.file

Do you have any idea about this situation?

@zhouweiwei
Copy link
Author

@cyberw
I think there is bug when using catch_response=True and stream=True。
Through the source, it can be seen that request_meta["response_length"] should be response.headers.get("content-length").
But in the execution result, request_meta["response_length"] is 0 and response.headers.get("content-length") is 14031744.

       if kwargs.get("stream", False):
            request_meta["response_length"] = int(response.headers.get("content-length") or 0)
        else:
            request_meta["response_length"] = len(response.content or b"")
with self.client.request("GET", downloadFileUrl, name=name, catch_response=True, context={}, stream=True) as resp, open(outputFile, "wb") as txt:
            
            print(resp.headers.get("content-length")) # 14031744
            print(resp.request_meta['response_length']) # 0

pftest-worker1-1  | 14031744
pftest-worker1-1  | 0

@cyberw
Copy link
Collaborator

cyberw commented Nov 6, 2023

Yea that looks strange. I guess what that code is actually trying to do is represent the number of bytes actually downloaded. Or something. But I dont know why...

@cyberw cyberw added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label Nov 12, 2023
Copy link

This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug invalid stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
Projects
None yet
Development

No branches or pull requests

2 participants