lemunozm / message-io

Fast and easy-to-use event-driven network library.
Apache License 2.0
1.11k stars 74 forks source link

does message-io support multiple threads? #110

Closed 18o closed 2 years ago

18o commented 2 years ago

it seems all adapter or worker are run in one thread, does it support multiple threads like tokio can let the program use whole processor .

lemunozm commented 2 years ago

Hi @18o,

As you have seen, each node uses one thread to read from the network for all the connections that the node has (you can use other threads to write while you are reading). If you need to get more parallel performance you could split your connections into several nodes, but reading from one connection only can be done from one thread.

tokio gets mixing thread and network events in a transparent way using an async/await api. Keep in mind that using 8 cores to read from one connection in tokio will not be faster than using 1 core to read from one connection. What tokio's offers is an automatic load balance across multiple connections in multiple threads. In scenarios with more connections than threads, you will take better advantage of your processor.

18o commented 2 years ago

thanks for your response, i'll try use message-io in my project instead of tokio as it's really tiny and simple

lemunozm commented 2 years ago

I'm glad to hear that! 😃

The intention of message-io is to leave things as simple as possible (without losing performance as far as possible). I also like so much tokio, and use it in other projects, but the programming complexity is higher than message-io. It all depends on the target of your application.