Closed rcloran closed 1 year ago
Since this also moves the start time timer to the top of the loop, before the echos are sent, it'll end up reducing the actual max_rtt -- though this is probably only meaningful when pinging a very large number of hosts. If that's not desirable, that might make the goal of reducing slew impossible, but the reduced wakeups might still be worthwhile.
After toying with this a bit and thinking about it, I don't think the goal of getting the slew fixed really fits here. So I'll update with a simplified PR that just reduces jitter and wakeups.
After toying with this a bit and thinking about it, I don't think the goal of getting the slew fixed really fits here. So I'll update with a simplified PR that just reduces jitter and wakeups.
Right, I don't think we want to adjust slew here for this case. Addressing jitter seems reasonable to me
Playing around some more ... there's another potential downside to this. It now reads Instant::now() twice per packet received; once for the RTT and once for the timeout. AIUI, this is a system call each time (I'll check that at some point), which could be a performance problem for a large number of targets.
An alternative is to use the RTT from the listener. The downside of that is that it doesn't take time taken for the message to get through the thread channel into account.
This may be a non-issue. I've been trying to benchmark against a small number of hosts on my home network, and see changes, but they are probably within noise as I haven't been super careful about how I'm performing the measurements.
Happy for you to let this PR linger until I'm a bit more clear on the effects of it, or, if you have opinions I'd be happy to listen.
This may be a non-issue. I've been trying to benchmark against a small number of hosts on my home network, and see changes, but they are probably within noise as I haven't been super careful about how I'm performing the measurements.
I reworked the bench setup to use criterion and cargo-flamegraph, pinging 127.0.0.{1..255}
, and seem to be getting reliable (enough) results. In this setup the time is heavily dominated by time in sendto(2)
. The only samples I could find to do with time (clock_gettime(3)
and mach_absolute_time
) were about 0.03% of total time spent in the program, though that includes setup (which seems to take a considerable fraction).
I think performance of this patch is a non-issue.
The ping loop has a
recv_timeout()
with a timeout of 100ms, and separately checks whether the deadline has passed. This causes some minor problems:In a client application, I logged the difference between arrival times of pings to one host on my local network (while also pinging a few others):
This change uses an alternative method, allowing timeout to be up to the maximum amount of time remaining. This reduces the jitter substantially: