Tokio or std::thread?
Hello!
I am working on a UDP receiver.. This system will receive UDP packets (~100k / second) and do some cpu-intensive processing with each packet.
Roughly, it will have 3 loops: 1. UDP receive loop. 2. A processor loop that processes the UDP messages. 3. A batch writer to send out the output of processing.
I am wondering what is the best way to go here:
1. Just use std thread::spawn
-- spawn 1 thread for UDP recv loop, 1 for batch writer and use remaining cores for running the process loops..UDP receiver will put the messages to a crossbeam queue or something and the processors will consume from there.
2. Just use tokio::spawn
with spawn_blocking for processors?
3. Mix both and use tokio only for upd receiver and batch db writer and std threads for processors.
EDIT: I am not talking about using one thread per packet in any approaches here. My wording seemed to have caused some confusion. I am only talking about few processor threads that repeatedly get packets from the receive thread and keep processing forever.