prometheus-community / pro-bing

A library for creating continuous probers
MIT License
345 stars 60 forks source link

High concurrency situation, returning packet loss, #104

Open blade83lee opened 6 months ago

blade83lee commented 6 months ago

High concurrency situation, returning packet loss, 2024/05/14 18:44:32 ping.go:201: D! no packets received, stats: &{{0 5 0 100 10.10.25.117 10.10.25.117 [] 0s 0s 0s 0s} 0} but tcpdump has packet return 18:44:27.903699 IP 10.4.3.20 > 10.10.25.117: ICMP echo request, id 22102, seq 0, length 64 18:44:27.925773 IP 10.10.25.117> 10.4.3.20: ICMP echo reply, id 22102, seq 0, length 64 18:44:28.904025 IP 10.4.3.20 > 10.10.25.117: ICMP echo request, id 22102, seq 1, length 64 18:44:28.926564 IP 10.10.25.117 > 10.4.3.20: ICMP echo reply, id 22102, seq 1, length 64 18:44:29.903706 IP 10.4.3.20 > 10.10.25.117: ICMP echo request, id 22102, seq 2, length 64 18:44:29.928764 IP 10.10.25.117 > 10.4.3.20: ICMP echo reply, id 22102, seq 2, length 64 18:44:30.903703 IP 10.4.3.20 > 10.10.25.117: ICMP echo request, id 22102, seq 3, length 64 18:44:30.927299 IP 10.10.25.117 > 10.4.3.20: ICMP echo reply, id 22102, seq 3, length 64 18:44:31.903708 IP 10.4.3.20 > 10.10.25.117: ICMP echo request, id 22102, seq 4, length 64 18:44:31.926030 IP 10.10.25.117 > 10.4.3.20: ICMP echo reply, id 22102, seq 4, length 64

How to optimize

ZhaoBaymax commented 1 month ago

On the sending end: the CPU will allocate a socket connection for each ICMP. That is to say, even in the case of coroutines, it is necessary to wait for the CPU to switch contexts. The start time is calculated in user mode, and there is still some time before the packet is actually sent out. Similarly, on the receiving end, this situation also exists. You can check the scheduling time of the service CPU to confirm this problem.