High performance udp tokio code?

  1. Is there something more idiomatic than tokio_udp_rate_test/main.rs at master · dwarfhack/tokio_udp_rate_test · GitHub ?

  2. Is tokio_udp_rate_test/main.rs at master · dwarfhack/tokio_udp_rate_test · GitHub multi threaded ?

  3. 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

Some comments:

  1. join_all is generally not efficient, though it doesn't matter for the particular use-case in your snippet.
  2. You shouldn't use SystemTime for measuring durations. Use Instant instead.
  3. In Tokio, the unit of parallelism is calls to tokio::spawn (or rt.spawn). Since you only have two, you will use at most two threads.
  4. To parallelize UdpSocket, you should call recv_from from several threads at the same time. I don't know how well this works though.
  5. The bincode::deserialize call should probably be given a slice that doesn't include stuff past the end of the packet.
1 Like

@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.