Experience in writing asynchronous polling for network devices

The basic idea behind asynchronous polling

Asynchrony allows you to greatly increase the parallelism of work. In the case of network communication and SNMP retrieval, the waiting times for responses are long, which allows the program to do something useful until the response arrives.





There are "synchronous" ways to implement parallelism - forks, threads. It is easy from the point of view of writing a program, but it is very “expensive” in terms of OS resources.





A bit of math

Mathematics will be engineering and approximate, accuracy 20%





I wanted to poll 100 thousand devices using 100 metrics and poll each device once every 5 minutes , with a margin of once a minute.  





That is, you need to shoot 10 million metrics per minute or 150 thousand per second.  I will round up to 100 thousand metrics per second.





Polling for one metric takes about 5ms: 4ms for the device, + 1ms for processing.





This means that one synchronous thread can process 200 metrics per second, or 500 synchronous threads are needed. Quite realistic.





(Everything, the end, there is nothing more to write)





In fact, this is just the beginning. The trick is not in the ideality of the world, but in the loss of responses to requests. Losses occur due to loss of traffic or inaccessibility of devices.





2 , «» 2000









3% . – , , .





, 3% 2000.





c 15,5 .





, 5 , 95 . , 125 800 . , .





– __ . – 800 , , .





, 3%, 20% 100% ?





,





– ,  – « X .   , 10 , , 2 ».





, , 45%, 99% .





: 100% . , , 30 ?  - 7 .









, , , Shared Memory . SNMP Net-SNMP





– ,





1 : « – , »

, ?





SNMP, , SNMP, , - :





:





First implementation of parallel polling

, . , , , , -.





– – 2 , . :





Waiting for timeouts is huge compared to normal responses

, 100- .





– , , .





«» .





:





2 : «- »

, , . . . - , .





. : .





2-3 3-4 , .





, , . , .





3 : « »

, . , SNMP UDP .





, :





, , , , .





3.5 : « , »

«» . . .





.





, . ,   3-4 2-4 .





– , - . . : , , , Net:SNMP.





, 60-70 . , , .





4 : « , »

, «» , .





4 , – , . , – .  





4.0 , «» . :





– – – , , .





- . SNMP, 48 .





- . 2 100% 15 30 720 ! 30 48 .





, , , – IP RAW socket.





120-140 .





30-40 , , 50% . 





:

1 4 2 . 2-3 -.





?





- « ».  





, .





, 15 , «».





, - . – .





.








All Articles