… | |
… | |
32 | |
32 | |
33 | Also, the Net::SNMP scheduler is very inefficient with respect to both CPU |
33 | Also, the Net::SNMP scheduler is very inefficient with respect to both CPU |
34 | and memory usage. Most AnyEvent backends (including the pure-perl backend) |
34 | and memory usage. Most AnyEvent backends (including the pure-perl backend) |
35 | fare much better than the Net::SNMP dispatcher. |
35 | fare much better than the Net::SNMP dispatcher. |
36 | |
36 | |
37 | Another major added fetaure of this module over Net::SNMP is automatic |
37 | Another major added feature of this module over Net::SNMP is automatic |
38 | rate-adjustments: Net::SNMP is so slow that firing a few thousand |
38 | rate-adjustments: Net::SNMP is so slow that firing a few thousand |
39 | requests can cause many timeouts simply because Net::SNMP cannot process |
39 | requests can cause many timeouts simply because Net::SNMP cannot process |
40 | the replies in time. This module automatically adapts the send rate to |
40 | the replies in time. This module automatically adapts the send rate to |
41 | avoid false timeouts caused by slow reply processing. |
41 | avoid false timeouts caused by slow reply processing. |
42 | |
42 | |
43 | A potential disadvantage of this module is that replacing the dispatcher |
43 | A potential disadvantage of this module is that replacing the dispatcher |
44 | is not at all a documented thing to do, so future changes in Net::SNP |
44 | is not at all a documented thing to do, so future changes in Net::SNMP |
45 | might break this module (or the many similar ones). |
45 | might break this module (or the many similar ones). |
46 | |
46 | |
47 | This module does not export anything and does not require you to do |
47 | This module does not export anything and does not require you to do |
48 | anything special apart from loading it I<before doing any non-blocking |
48 | anything special apart from loading it I<before doing any non-blocking |
49 | requests with Net::SNMP>. It is recommended but not required to load this |
49 | requests with Net::SNMP>. It is recommended but not required to load this |
… | |
… | |
69 | case, this can lead to packet loss, when the receive queue overflows and |
69 | case, this can lead to packet loss, when the receive queue overflows and |
70 | the kernel can no longer accept new packets. |
70 | the kernel can no longer accept new packets. |
71 | |
71 | |
72 | To avoid this, you can (and should) limit the number of outstanding |
72 | To avoid this, you can (and should) limit the number of outstanding |
73 | requests to a number low enough so that parsing time doesn't introduce |
73 | requests to a number low enough so that parsing time doesn't introduce |
74 | noticable delays. |
74 | noticeable delays. |
75 | |
75 | |
76 | Unfortunately, this number depends not only on processing speed and load |
76 | Unfortunately, this number depends not only on processing speed and load |
77 | of the machine running Net::SNMP, but also on the network latency and the |
77 | of the machine running Net::SNMP, but also on the network latency and the |
78 | speed of your SNMP agents. |
78 | speed of your SNMP agents. |
79 | |
79 | |
80 | AnyEvent::SNMP tries to dynamically adjust this number dynamically upwards |
80 | AnyEvent::SNMP tries to dynamically adjust this number upwards and |
81 | and downwards. |
81 | downwards. |
82 | |
82 | |
83 | Increasing C<$MAX_OUTSTANDING> will not automatically use the |
83 | Increasing C<$MAX_OUTSTANDING> will not automatically use the |
84 | extra request slots. To increase C<$MAX_OUTSTANDING> and make |
84 | extra request slots. To increase C<$MAX_OUTSTANDING> and make |
85 | C<AnyEvent::SNMP> make use of the extra paralellity, call |
85 | C<AnyEvent::SNMP> make use of the extra parallelity, call |
86 | C<AnyEvent::SNMP::set_max_outstanding> with the new value, e.g.: |
86 | C<AnyEvent::SNMP::set_max_outstanding> with the new value, e.g.: |
87 | |
87 | |
88 | AnyEvent::SNMP::set_max_outstanding 500; |
88 | AnyEvent::SNMP::set_max_outstanding 500; |
89 | |
89 | |
90 | Although due to the dynamic adjustment, this might have little lasting |
90 | Although due to the dynamic adjustment, this might have little lasting |
… | |
… | |
103 | When AnyEvent::SNMP handles $MAX_RECVQUEUE or more packets per iteration |
103 | When AnyEvent::SNMP handles $MAX_RECVQUEUE or more packets per iteration |
104 | it will reduce $MAX_OUTSTANDING. If it handles less than $MIN_RECVQUEUE, |
104 | it will reduce $MAX_OUTSTANDING. If it handles less than $MIN_RECVQUEUE, |
105 | it increases $MAX_OUTSTANDING. |
105 | it increases $MAX_OUTSTANDING. |
106 | |
106 | |
107 | This has the result of adjusting the number of outstanding requests so that |
107 | This has the result of adjusting the number of outstanding requests so that |
108 | the recv queue is between the minimum and maximu, usually. |
108 | the recv queue is between the minimum and maximum, usually. |
109 | |
109 | |
110 | This algorithm works reasonably well as long as the responses, response |
110 | This algorithm works reasonably well as long as the responses, response |
111 | latencies and processing times are the same size per packet on average. |
111 | latencies and processing times are the same per packet on average. |
112 | |
112 | |
113 | =back |
113 | =back |
114 | |
114 | |
115 | =head1 COMPATIBILITY |
115 | =head1 COMPATIBILITY |
116 | |
116 | |
… | |
… | |
135 | |
135 | |
136 | =cut |
136 | =cut |
137 | |
137 | |
138 | package AnyEvent::SNMP; |
138 | package AnyEvent::SNMP; |
139 | |
139 | |
140 | no warnings; |
140 | use common::sense; |
141 | use strict qw(subs vars); |
|
|
142 | |
141 | |
143 | # it is possible to do this without loading |
142 | # it is possible to do this without loading |
144 | # Net::SNMP::Dispatcher, but much more awkward. |
143 | # Net::SNMP::Dispatcher, but much more awkward. |
145 | use Net::SNMP::Dispatcher; |
144 | use Net::SNMP::Dispatcher; |
146 | |
145 | |
|
|
146 | # we could inherit fro Net:SNMP::Dispatcher, but since this is undocumented, |
|
|
147 | # I'd rather see it die (and reported) than silenty and subtly fail. |
|
|
148 | *msg_handle_alloc = \&Net::SNMP::Dispatcher::msg_handle_alloc; |
|
|
149 | |
147 | sub Net::SNMP::Dispatcher::instance { |
150 | sub Net::SNMP::Dispatcher::instance { |
148 | AnyEvent::SNMP:: |
151 | AnyEvent::SNMP:: |
149 | } |
152 | } |
150 | |
153 | |
151 | use Net::SNMP (); |
154 | use Net::SNMP (); |
152 | use AnyEvent (); |
155 | use AnyEvent (); |
153 | |
156 | |
154 | our $VERSION = '1.0'; |
157 | our $VERSION = '6.02'; |
155 | |
158 | |
156 | $Net::SNMP::DISPATCHER = instance Net::SNMP::Dispatcher; |
159 | $Net::SNMP::DISPATCHER = instance Net::SNMP::Dispatcher; |
157 | |
160 | |
158 | our $MESSAGE_PROCESSING = $Net::SNMP::Dispatcher::MESSAGE_PROCESSING; |
161 | our $MESSAGE_PROCESSING = $Net::SNMP::Dispatcher::MESSAGE_PROCESSING; |
159 | |
162 | |
… | |
… | |
254 | |
257 | |
255 | # Set the error if applicable. |
258 | # Set the error if applicable. |
256 | $msg->error ($MESSAGE_PROCESSING->error) if $MESSAGE_PROCESSING->error; |
259 | $msg->error ($MESSAGE_PROCESSING->error) if $MESSAGE_PROCESSING->error; |
257 | |
260 | |
258 | # Notify the command generator to process the response. |
261 | # Notify the command generator to process the response. |
259 | $msg->process_response_pdu; |
262 | # Net::SNMP calls process_response_pdu, which simply calls callback_execute, |
|
|
263 | # but some errors cause $msg to be of type Net::SNMP::Message, not Net::SMMP::PDU, |
|
|
264 | # so we call the underlying callback_execute method which exists on both and |
|
|
265 | # seems to do the right thing. |
|
|
266 | $msg->callback_execute; |
260 | |
267 | |
261 | # Cancel the timeout. |
268 | # Cancel the timeout. |
262 | my $rtimeout_w = $msg->timeout_id; |
269 | my $rtimeout_w = $msg->timeout_id; |
263 | if ($$rtimeout_w) { |
270 | if ($$rtimeout_w) { |
264 | undef $$rtimeout_w; |
271 | undef $$rtimeout_w; |
… | |
… | |
338 | kick_job; |
345 | kick_job; |
339 | |
346 | |
340 | 1 |
347 | 1 |
341 | } |
348 | } |
342 | |
349 | |
343 | sub activate($) { |
350 | sub loop($) { |
344 | while ($BUSY) { |
351 | while ($BUSY) { |
345 | $DONE = AE::cv; |
352 | $DONE = AE::cv; |
346 | $DONE->recv; |
353 | $DONE->recv; |
347 | undef $DONE; |
354 | undef $DONE; |
348 | } |
355 | } |
349 | } |
356 | } |
350 | |
357 | |
|
|
358 | *activate = \&loop; # 5.x compatibility? |
|
|
359 | *listen = \&loop; # 5.x compatibility? |
|
|
360 | |
351 | sub one_event($) { |
361 | sub one_event($) { |
352 | # should not ever be used |
362 | # should not ever be used |
353 | AnyEvent->one_event; #d# todo |
363 | AnyEvent->one_event; #d# todo |
354 | } |
364 | } |
355 | |
365 | |
356 | sub set_max_outstanding($) { |
366 | sub set_max_outstanding($) { |
357 | $MAX_OUTSTANDING = $_[0]; |
367 | $MAX_OUTSTANDING = $_[0]; |
358 | kick_job; |
368 | kick_job; |
359 | } |
369 | } |
360 | |
370 | |
|
|
371 | # not provided yet: |
|
|
372 | # schedule # apparently only used by Net::SNMP::Dispatcher itself |
|
|
373 | # register # apparently only used by Net::SNMP::Dispatcher itself |
|
|
374 | # deregister # apparently only used by Net::SNMP::Dispatcher itself |
|
|
375 | # cancel # apparently only used by Net::SNMP::Dispatcher itself |
|
|
376 | # return_response_pdu # apparently not used at all? |
|
|
377 | # error # only used by Net::SNMP::Dispatcher itself? |
|
|
378 | # debug # only used by Net::SNMP::Dispatcher itself? |
|
|
379 | |
361 | =head1 SEE ALSO |
380 | =head1 SEE ALSO |
362 | |
381 | |
363 | L<AnyEvent>, L<Net::SNMP>, L<Net::SNMP::XS>, L<Net::SNMP::EV>. |
382 | L<AnyEvent>, L<Net::SNMP>, L<Net::SNMP::XS>, L<Net::SNMP::EV>. |
364 | |
383 | |
365 | =head1 AUTHOR |
384 | =head1 AUTHOR |