Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've tried two methods, one in which I'm simply iterating from 0 to n and calling my sub to send a cold start trap. This is relatively fast until I start increasing n. My second method is what I think is correct using threads. This seems a lot slower. Is it possible to spawn multiple threads using the SNMP module?
Any suggestions would be greatly appreciated.
#!C:/perl/bin/perl use warnings; use strict; use threads; use threads::shared; use Net::SNMP; use Sys::Hostname('hostname'); my @childs = (); my $t0 = Time::HiRes::time; for(0..10) { # sendColdStart(); push @childs, threads->create("sendColdStart"); } my $t1 = Time::HiRes::time; my $elapsed = $t1 - $t0; print "\nElapsed Time: $elapsed\n"; foreach my $child (@childs){ $child->join(); } sub sendColdStart { my $host = hostname(); my $addr = join( ".", unpack( 'C4', ( ( gethostbyname($host) )[4] +)[0] ) ); my $oid = '1.3.6.1.4'; my $source_ip = '125.78.179.6'; my $generic = 0; my @trapvars = (); my ($session, $error) = Net::SNMP->session( -hostname => $addr, -community => 'public', -version => 'snmpv1', -port => 162 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $result = $session->trap( -enterprise => $oid, -agentaddr => $source_ip, -generictrap => $generic, -specifictrap => '0', -varbindlist => \@trapvars ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } $session->close; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net SNMP and threads
by Anonymous Monk on Nov 19, 2005 at 10:00 UTC |