The issue is that now my code is way slower than before, I guess because of the fact that it's not multi threaded anymore.
So I have 2 questions :
How should I make my new version using async multi threaded ? Should I still use the threadpool crates ? or something else ?
The second question is, why when I do only one request without threadpool the async version is still slower ? Am I doing something wrong ?
why the first code here is faster than the second one
// without using async version of reqwest : (faster, why?)
reqwest::get(url.as_str())
.expect("Error GET request")
.text()
.expect("Error parsing response")
.lines()
.map(|item| item.to_string())
.filter(|file| whitelist.iter().any(|ext| file.ends_with(ext)))
.collect()
// with using async version of reqwest : (slower)
reqwest::get(url.as_str()).await
.expect("Error GET request")
.text().await
.expect("Error parsing response")
.lines()
.map(|item| item.to_string())
.filter(|file| whitelist.iter().any(|ext| file.ends_with(ext)))
.collect()
Sorry for my english, but i will try to explain it,
for the first question, you can use rayon to get multithreathing and get a multithreahd in async way of getting the urls
second the interaction of the async with the operating system is more faster than the sync version but in the code that you have posted the operations with the file are not async, and this is a problem.
can you post a benchmark to see the diferences? you are compiling with --release?
Is each individual request slower, or are you seeing less parallelism? As for how you do multithreading, you can spawn each request on a separate Tokio task with tokio::spawn. You should not try to make async code multithreaded by using rayon. Rayon is for non-async heavy computations, not IO.
I think each individual request is slower because when I call "run_url()" which makes only one request it is significantly lower on the new version(even with --release)
Normally I would expect async reqwest to perform about the same as sync. Can you give more details? Perhaps a minimal example with the issue or link to code?
I tried to make a minimal example with this request and the map etc but like you said the time is approximately the same for both so I'm kinda lost in why my project is slower with only this change..