Open AmbitionXiang opened 2 years ago
How much RAM you have? That code uses a lot of RAM.
This uses 3 GB RAM:
let data_bytes = hyper::body::to_bytes(res.into_body()).await;
This copies the data and uses another 3 GB RAM for total of 6 GB RAM:
bytes.to_vec().len()
Then at server this uses 3 or 6 GB RAM (I'm not sure if this copies data or not):
let body = Body::from(vec![1u8; 3_000_000_000]);
I'm not sure if that error can result from running out of RAM, but to decrease RAM usage firstly you can use bytes.len()
instead of bytes.to_vec().len()
to avoid copying. Then using streaming instead of keeping all data in RAM would decrease RAM usage even more.
@malaire My server is equipped with 377GB RAM. So it seems not the reason.
It seems that hyper
uses i32
somewhere and overflow triggers the error, as the code doesn't trigger the error until I change Body::from(vec![1u8; 3_000_000_000])
to Body::from(vec![1u8; 2147483648])
or larger
Ah, thanks for reminding me. This is likely because of https://github.com/hyperium/h2/issues/471.
Hi, there. As I try to get a large amount of data (e.g., 3GB) from the server, the fetching fails. The code is shown as follows.
Client side
Cargo.toml
src/main.rs
Server side
Cargo.toml
src/main.rs
And the result seen from the client is
How to solve it?