Low-latency communication #3046
Replies: 2 comments 1 reply
-
You can do profiling for further insights: $ perf stat -r3 -e syscalls:sys_enter_futex,syscalls:sys_enter_read,syscalls:sys_enter_sched_yield,syscalls:sys_enter_epoll_pwait,context-switches,cycles:k,cycles:u,instructions,task-clock ./target/release/channel_latency > without_sleep with yield:
with sleep:
without both: (only tx.send(Instant::now()).await.unwrap())
|
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! I'm not super familiar with the low-level details and syscalls, but from what it looks like the culprit are the many process context switches? And the only way to avoid that would be to spin in a loop as opposed to using something that uses epoll such as blocking sockets or sleep? Does that sound right? |
Beta Was this translation helpful? Give feedback.
-
I've been investigating async for processing that requires low end-to-end latency. I wrote a simple benchmark that measures the average time between channel sends and receives:
The output of this is
495ns
on my machine. This is great, just what I was looking for. However, the times increase by 10-15x when I uncomment thesleep
line in the code above. And by more if I consider the 99th percentile instead of the average. It doesn't need to be sleep - I get the same behavior when messages arrive at a slower pace coming from IO for example. The sleep is just there to emulate this.Now, it kind of makes sense to me that idling between channels sends would result in the CPU doing other stuff and overwriting data in caches, etc. That would make it slower, but not 10-15x slower. So I'm curious, what exactly is happening here that leads to this latency increase?
Beta Was this translation helpful? Give feedback.
All reactions