ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-SNMP/SNMP.pm
(Generate patch)

Comparing AnyEvent-SNMP/SNMP.pm (file contents):
Revision 1.10 by root, Sun Oct 31 18:15:22 2010 UTC vs.
Revision 1.14 by root, Wed Oct 9 18:22:59 2019 UTC

32 32
33Also, the Net::SNMP scheduler is very inefficient with respect to both CPU 33Also, the Net::SNMP scheduler is very inefficient with respect to both CPU
34and memory usage. Most AnyEvent backends (including the pure-perl backend) 34and memory usage. Most AnyEvent backends (including the pure-perl backend)
35fare much better than the Net::SNMP dispatcher. 35fare much better than the Net::SNMP dispatcher.
36 36
37Another major added fetaure of this module over Net::SNMP is automatic 37Another major added feature of this module over Net::SNMP is automatic
38rate-adjustments: Net::SNMP is so slow that firing a few thousand 38rate-adjustments: Net::SNMP is so slow that firing a few thousand
39requests can cause many timeouts simply because Net::SNMP cannot process 39requests can cause many timeouts simply because Net::SNMP cannot process
40the replies in time. This module automatically adapts the send rate to 40the replies in time. This module automatically adapts the send rate to
41avoid false timeouts caused by slow reply processing. 41avoid false timeouts caused by slow reply processing.
42 42
43A potential disadvantage of this module is that replacing the dispatcher 43A potential disadvantage of this module is that replacing the dispatcher
44is not at all a documented thing to do, so future changes in Net::SNP 44is not at all a documented thing to do, so future changes in Net::SNMP
45might break this module (or the many similar ones). 45might break this module (or the many similar ones).
46 46
47This module does not export anything and does not require you to do 47This module does not export anything and does not require you to do
48anything special apart from loading it I<before doing any non-blocking 48anything special apart from loading it I<before doing any non-blocking
49requests with Net::SNMP>. It is recommended but not required to load this 49requests with Net::SNMP>. It is recommended but not required to load this
69case, this can lead to packet loss, when the receive queue overflows and 69case, this can lead to packet loss, when the receive queue overflows and
70the kernel can no longer accept new packets. 70the kernel can no longer accept new packets.
71 71
72To avoid this, you can (and should) limit the number of outstanding 72To avoid this, you can (and should) limit the number of outstanding
73requests to a number low enough so that parsing time doesn't introduce 73requests to a number low enough so that parsing time doesn't introduce
74noticable delays. 74noticeable delays.
75 75
76Unfortunately, this number depends not only on processing speed and load 76Unfortunately, this number depends not only on processing speed and load
77of the machine running Net::SNMP, but also on the network latency and the 77of the machine running Net::SNMP, but also on the network latency and the
78speed of your SNMP agents. 78speed of your SNMP agents.
79 79
80AnyEvent::SNMP tries to dynamically adjust this number dynamically upwards 80AnyEvent::SNMP tries to dynamically adjust this number upwards and
81and downwards. 81downwards.
82 82
83Increasing C<$MAX_OUTSTANDING> will not automatically use the 83Increasing C<$MAX_OUTSTANDING> will not automatically use the
84extra request slots. To increase C<$MAX_OUTSTANDING> and make 84extra request slots. To increase C<$MAX_OUTSTANDING> and make
85C<AnyEvent::SNMP> make use of the extra paralellity, call 85C<AnyEvent::SNMP> make use of the extra parallelity, call
86C<AnyEvent::SNMP::set_max_outstanding> with the new value, e.g.: 86C<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
90Although due to the dynamic adjustment, this might have little lasting 90Although due to the dynamic adjustment, this might have little lasting
103When AnyEvent::SNMP handles $MAX_RECVQUEUE or more packets per iteration 103When AnyEvent::SNMP handles $MAX_RECVQUEUE or more packets per iteration
104it will reduce $MAX_OUTSTANDING. If it handles less than $MIN_RECVQUEUE, 104it will reduce $MAX_OUTSTANDING. If it handles less than $MIN_RECVQUEUE,
105it increases $MAX_OUTSTANDING. 105it increases $MAX_OUTSTANDING.
106 106
107This has the result of adjusting the number of outstanding requests so that 107This has the result of adjusting the number of outstanding requests so that
108the recv queue is between the minimum and maximu, usually. 108the recv queue is between the minimum and maximum, usually.
109 109
110This algorithm works reasonably well as long as the responses, response 110This algorithm works reasonably well as long as the responses, response
111latencies and processing times are the same size per packet on average. 111latencies 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
138package AnyEvent::SNMP; 138package AnyEvent::SNMP;
139 139
140no warnings; 140use common::sense;
141use 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.
145use Net::SNMP::Dispatcher; 144use 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
147sub Net::SNMP::Dispatcher::instance { 150sub Net::SNMP::Dispatcher::instance {
148 AnyEvent::SNMP:: 151 AnyEvent::SNMP::
149} 152}
150 153
151use Net::SNMP (); 154use Net::SNMP ();
152use AnyEvent (); 155use AnyEvent ();
153 156
154our $VERSION = '1.0'; 157our $VERSION = '6.02';
155 158
156$Net::SNMP::DISPATCHER = instance Net::SNMP::Dispatcher; 159$Net::SNMP::DISPATCHER = instance Net::SNMP::Dispatcher;
157 160
158our $MESSAGE_PROCESSING = $Net::SNMP::Dispatcher::MESSAGE_PROCESSING; 161our $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
343sub activate($) { 350sub 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
351sub one_event($) { 361sub 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
356sub set_max_outstanding($) { 366sub 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
363L<AnyEvent>, L<Net::SNMP>, L<Net::SNMP::XS>, L<Net::SNMP::EV>. 382L<AnyEvent>, L<Net::SNMP>, L<Net::SNMP::XS>, L<Net::SNMP::EV>.
364 383
365=head1 AUTHOR 384=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines