Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LatencyTestWithChan ¶
func LatencyTestWithChan(addrs []string, c chan<- Result, loops int, gos int, retry bool, timeout time.Duration, names ...string) error
LatencyTestWithChan test latency between remote and local, and store valid remote's index in c the faster the less for remote's index
if you do not want a result which sored ,this is better
Args: addrs -> []string{"www.bing.com","192.168.12.1"} c -> store result for goroutine loops -> ping times gos -> concurrency numbers retry -> wheather try to use net.Dial to test latency after ping failed timeout -> timeout for ping and net.Dial names -> [optional] url's name exist a map relation
this is based on icmp protocl, requiring to run as privileged otherwise block
Types ¶
type Result ¶
type Result struct { //Name is mirror in eng short Name string //Address is IP or domain Address string //Latency in ms Latency time.Duration //Ping if remote can be ping successfuly Ping bool //Error for invalid remote host Error error }
Result is just result
type Results ¶
type Results []Result
Results for results
func LatencyTest ¶
func LatencyTest(addrs []string, loops int, retry bool, gos int, timeout time.Duration, names ...string) (rets Results, err error)
LatencyTest test latency between remote and local, and store valid remote's index in c tresult are stored in rets,the faster remote host the less index are
Args: addrs -> []string{"www.bing.com","192.168.12.1"} loops -> ping times retry -> wheather try to use net.Dial to test latency after ping failed gos -> concurrency numbers timeout -> timeout for ping and net.Dial names -> [optional] url's name exist a map relation
for improving efficiency to use LatencyTestWithChan in goroutine instead of this but this provide a sort method(Results.SortByDuration) This is based on icmp protocl, requiring to run as privileged otherwise block
func (Results) SortByDuration ¶
func (r Results) SortByDuration()
SortByDuration just sort follow duration Using insert sort