pysnmp性能再测试

这次使用snmpgettable方法来测试getnext方法的性能,获取ifindex节点,大约74条数据,

可样可以避免循环对测试结果的影响。

c的

time snmpwalk -c public 192.168.6.87  ifindex
real    0m0.480s
user    0m0.077s
sys     0m0.029s
-bash-3.00$


perl的  total 0.777080059051514.

#!/usr/local/bin/perl
#testsnmpwalk.pl
use strict;
use Net::SNMP;
use Time::HiRes qw(time);

unshift (@INC,"/slview/nms/lib");
#require ("DevPerfPub.pl");
require ("Debug.pl");
require ("SnmpUtil.pl");

my ($ip,$comm,$oid);

my $ArgNum = scalar(@ARGV);
if ($ArgNum == 0){
	print "[error]usage:testsnmp.pl ip commu oid [version].\n";
	$ip="192.168.6.87";
	$comm="public";
	$oid=".1.3.6.1.2.1.2.2.1.1";
}
else{
	 $ip=$ARGV[0];
	 $comm=$ARGV[1];
	 $oid=$ARGV[2];
}
my $loopnum=5;

my $mib;
my @Index;
my @Oids=($oid);
my $DevColInfo;
$DevColInfo->{'LoopAddress'}=$ip;
$DevColInfo->{'SNMPCommunity'}=$comm;
$DevColInfo->{'SnmpVersion'}="v1";
my $CurValueRef={};#初始化参考变量
my $SnmpTimeOut=2;
my $SnmpRetry=1;

my $sec1=time();

	my $sess = &CreateSnmpSession_ext($mib,$DevColInfo,$SnmpTimeOut,$SnmpRetry,$CurValueRef);
	if (!defined($sess)){
		my $Detail="Create SNMP session failed: [$DevColInfo->{'LoopAddress'},$DevColInfo->{'SNMPCommunity'}].\n";
			&Debug($Detail,4);
			
	}
	&Debug("create snmp session ok.\n");
	my ($Error,@Result) = &SnmpGetTable($sess,$mib,\@Index,@Oids);
	for my  $k (0..$#Index){
   print("$Result[0][$k].\n");
  }

my $sec2=time()-$sec1;;
print "total $sec2.\n";

python的  550ms,这回表现很不错,和perl和c相当了,甚至比perl还要好一点

E:\work\python\snmp>c:\python25\python.exe c:\Python25\lib\timeit.py -s "import
snmpnextperf" snmpnextperf.runit(1)
10 loops, best of 3: 550 msec per loop

 

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# GET Command Generator
#同步方式的snmpget性能测试

from pysnmp.entity.rfc3413.oneliner import cmdgen


def snmpget():
	errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(
	  #0代表v1,1代表v2c
		cmdgen.CommunityData('my-agent', 'public', 1),
		cmdgen.UdpTransportTarget(('192.168.6.87', 161)),
		#'1.3.6.1.2.1.1.1.0',
		#'1.3.6.1.2.1.1.2.0',
		#'1.3.6.1.2.1.1.3.0',
		'1.3.6.1.2.1.2.2.1.1'
		#(1,3,6,1,2,1,2,2,1,1)

	)
		#print(varBinds)
		#print str(varBinds[0][0][1]);
	
def runit(loop=1):
    for i in range(loop):
        snmpget()
        #print i

if __name__ == "__main__":
    runit(loop=1)




 

阅读更多
换一批

没有更多推荐了,返回首页