in reply to threads and SNMP Session

What exactly are you trying to acheive? If you are polling multiple hosts, starting a new thread for each device could cause you some scalability problems. I had a similar situation a few years ago. Over about 50 hosts, and the overhead required for each new process killed the PC. Using Net::SNMP in non-blocking mode allows you to do the job. In my case, I'm now polling about 200 devices at once, and all polls are fiinshed in about 12 seconds. Is this what you're trying to do, or am I way off?

Replies are listed 'Best First'.
Re^2: threads and SNMP Session
by Otogi (Beadle) on Dec 20, 2005 at 18:11 UTC
    I'm doing a walk on a each device for example to get the interface information on over 1000 devices at the same time ( it depends on whats needed by the engineer). I decided to leave the threads implementation because of the huge overhead and im currently using fork to initiate about 10 process to start each session with each device and its still not fast enough. I would appreciate if you go into more detail about your implementation. Thanks!
      You will need to read the Net::SNMP documentation several times before it sinks in properly, I found. Here's a quick example of how to get the IfInOctets and IfOutOctets for interface number 1 on multiple hosts in one hit. It's not much different from the examples in the docs, though:
      use warnings; use strict; use Net::SNMP; my $community="public"; # community string for devices my $interface_number=1; # interface number to poll my @ip_addresses=("192.168.5.242","192.168.11.34"); # Queue up a request to each host. foreach (@ip_addresses) { my ($session,$error)=Net::SNMP->session(-hostname=>"$_", -nonblocking=>1, -community=>"$community", -timeout=>2, -retries=>3, ); if (defined($session)) { my $in_oid=".1.3.6.1.2.1.2.2.1.10."."$interface_number"; # +OIDs to poll. my $out_oid=".1.3.6.1.2.1.2.2.1.16."."$interface_number"; my $uptime_oid=".1.3.6.1.2.1.1.3.0"; my @oids=($in_oid,$out_oid,$uptime_oid); my $result=$session->get_request( -varbindlist=>\@oids, callback=>[\&reply,$interface_number,$_] ); } else { print "Session not defined! $error\n"; } } # All requests are queued. Now dispatch them. snmp_dispatcher(); exit; # Sub "reply" is executed for each response from remote hosts. sub reply { my $obj=shift; my $interface=shift; my $ip_address=shift; if (!defined($obj->var_bind_list)) { warn "$ip_address SNMP Error.",$obj->error(),"\n"; return; } my $in_oid=".1.3.6.1.2.1.2.2.1.10."."$interface"; my $out_oid =".1.3.6.1.2.1.2.2.1.16."."$interface"; my $uptime_oid=".1.3.6.1.2.1.1.3.0"; my $uptime=$obj->var_bind_list->{$uptime_oid}; my $in=$obj->var_bind_list->{$in_oid}; my $out=$obj->var_bind_list->{$out_oid}; print "$ip_address interface number $interface bytes in: $in bytes + out: $out Uptime $uptime\n"; }

      Keep these things in mind when designing this:
      In non-blocking mode, it will queue all requests without actually dispatching them until you execute the snmp_dispatcher.
      At that point, your program will block until all requests have been finished.
      Each time a response is recieved, it will call the 'reply' subroutine.
      You only get control back to the main program after all requests have either completed or timed out.
      Good luck.