Is there something more idiomatic than tokio_udp_rate_test/main.rs at master · dwarfhack/tokio_udp_rate_test · GitHub ?
Is tokio_udp_rate_test/main.rs at master · dwarfhack/tokio_udp_rate_test · GitHub multi threaded ?
Where (if any) does the parallelism come from ? tokio_udp_rate_test/main.rs at master · dwarfhack/tokio_udp_rate_test · GitHub looks like a single thread of execution
join_allis generally not efficient, though it doesn't matter for the particular use-case in your snippet.
- You shouldn't use
SystemTimefor measuring durations. Use
- In Tokio, the unit of parallelism is calls to
rt.spawn). Since you only have two, you will use at most two threads.
- To parallelize
UdpSocket, you should call
recv_fromfrom several threads at the same time. I don't know how well this works though.
bincode::deserializecall should probably be given a slice that doesn't include stuff past the end of the packet.
@alice : Do you have example code that does it 'the right way'? (Above links were just from googling.)
If you want more info on how to call
recv_from from multiple threads, then what you do is put it in an
Arc and give a clone of the
Arc<UdpSocket> to different Tokio tasks. Then each task just does what your code does.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.