go-ping / ping

ICMP Ping library for Go
MIT License
1.33k stars 345 forks source link

Use exponential backoff for read deadline #162

Closed mem closed 3 years ago

mem commented 3 years ago

Before this change, pinging any target once takes ~ 100 ms (the time it takes for Run() to return, not the RTT). After this change, it takes a time comparable to the RTT. The change comes from ReadFrom blocking for the specified delay if the done signal hasn't fired yet. It also improves a little the time it takes to ping a single target multiple times.

Since this is exponential backoff in the way Ethernet does it (random delay, with an increasing maximum value, only changing in case of a timeout), the delay neither necessarily doubles nor increases each time the operation has to be retried, but it does eventually settle on the higher end of the possibilities if there are many timeouts.

Signed-off-by: Marcelo E. Magallon marcelo.magallon@grafana.com