prometheus-community / pro-bing

A library for creating continuous probers
MIT License
291 stars 49 forks source link

With a little concurrency, the detection quality is very poor and plummets #111

Open MrGlp opened 1 week ago

MrGlp commented 1 week ago

Please help me if you can, thank you very much, I have to fix this quickly to get off work and go on a date with Ms. Amin

issue: For the unit test below If the expectAppendTimes is 300, more than %50 AvgRtt is 100ms(time out) If the expectAppendTimes is 100, 100% AvgRtt is 50ms(not time out) I think there is a resource bottleneck that makes it impossible to be concurrent, the test environment is win11, and centos also reproduces the same similar problem, how to solve the optimization


func TestPingIPv4(t *testing.T) {
    ip := net.ParseIP(const_dc.LocalAddressIpv4)
    t.Log(ip.String())
    addrArr := []string{
        "www.baidu.com",
        "www.qq.com",
        "www.alibaba.com",
    }
    expectAppendTimes := 300
    for i := range iter.N(expectAppendTimes) {
        addrArr = append(addrArr, addrArr[i%3])
    }
    expectTimes := 1
    expectTimeDuration := 100 * time.Millisecond
    for iTmp, addrTmp := range addrArr {
        i := iTmp
        addr := addrTmp
        go func() {
            got, err := PingIPv4(addr, expectTimes, expectTimeDuration)
            if err != nil {
                t.Error(err.Error())
            }
            if got.PacketsRecv == 0 || got.AvgRtt > expectTimeDuration {
                t.Log(i, 100*time.Millisecond)
            } else {
                t.Log(i, got.AvgRtt)
            }
        }()
    }
    time.Sleep(time.Minute)
}