Imagine that I have a webserver that does the following:
-
Receives a GET Request with an ID.
-
Based on that ID, the server will query two data sources at the same time:
a. An external Webserver via REST
b. A Database -
Once those calls are both completed, it will combine the results and do some moderate/light processing (nothing too intensive).
-
It will return a result consisting of the processed data.
When programming a NodeJs WebServer, I only have access to a single thread of execution, so it is very easy for me to reason that it all of the above will occur in one thread. In exchange for this simplicity, I miss out on multicore processing.
However, I am curious how the above workflow would play out in Rust and Tokio.
If I am not mistaken, a Tokio server (possibly Hyper) will use async IO to receive all requests on a single thread. If I were performing the workflow I mentioned above, would it make sense (or is it even possible) to somehow share the same Async IO thread when contacting the webserver and database? Once those calls are made, would it make sense to perform the moderate/light processing on that same thread?
If the above is true, how would I be able to leverage more than one CPU core?
If not, would it make sense to have a single, separate running async IO thread for each possible outgoing call? Even if the last processing step is not heavy, would it make sense to send it to a threadpool?
I know that this is a abstract question, but I would really appreciate it if someone could clarify how to leverage multi processing in addition to Tokio.
Thank you very much.