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

.json() timed out when parsing large response #2153

Open
Arichy opened this issue Mar 5, 2024 · 5 comments
Open

.json() timed out when parsing large response #2153

Arichy opened this issue Mar 5, 2024 · 5 comments

Comments

@Arichy
Copy link

Arichy commented Mar 5, 2024

I'm fetching a large data in about 36MB:

let response = reqwest::blocking::get(&full_url)?.error_for_status()?;
let body: Value = response.json()?;

And it's easy to get a timed out error

decoding response body: operation timed out

I tried setting the timeout value to 90s, and it spent 87s to deserialize the data to json. It's too slow!
As a comparison, I saved the data into a json file and use serde_json to deserialize it directly:

let res: Value = serde_json::from_str(&file)?;

The cost turned out to be about 1s.

@mohe2015
Copy link

mohe2015 commented Mar 5, 2024

I think the .json() call includes downloading the response body so maybe your connection is just slow?

@Arichy
Copy link
Author

Arichy commented Mar 5, 2024

I think the .json() call includes downloading the response body so maybe your connection is just slow?

I'm not sure if the downloading process happens in .get or .json, but my network connection is not so slow as 80s.
I used postman and nodejs to send request, and it finished in 5s.

@mohe2015
Copy link

mohe2015 commented Mar 5, 2024

Did you try a release build for good measure?

@Arichy
Copy link
Author

Arichy commented Mar 5, 2024

Sorry, I made a mistake on the request cost. Actually it costed about 20s.
I've tested the release build, and the result was between 37 and 56s, still much more than 20s.
It's wired because the request costs 20s while the serde_json::from_str(&file) costs 1s, the total cost should be about 21s.

@LeoniePhiline
Copy link

Try setting the environment variable RUST_LOG to debug or trace if you are using tracing-subscriber.

This should help you determine where in the code the time is actually spent.

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

3 participants