etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
583 stars 201 forks source link

performance issue on FreeBSD #232

Open verb5 opened 5 years ago

verb5 commented 5 years ago

Hello everyone I have following problem on Freebsd 11 amd64 the code bellow executes 5 time slower on python3.7 then on python 2.7:

    from pysnmp.entity.rfc3413.oneliner import cmdgen

    errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(cmdgen.CommunityData('my-agent', comunity,0),cmdgen.UdpTransportTarget((host,161)),tmpOid)
result=varBinds[0][1]

    print(result)

any ideas what could be the cause ? . I tried this snippet on linux ubuntu and it works perfect on both python2.7 and python 3.7

etingof commented 5 years ago

It is hard to tell what the problem might be. May be it has something to do with Python 2.7 setup? Or some extension modules? It should not depend on pysnmp, I think...

One way to debug this may be first to rephrase you code to base on the latest pysnmp API.

verb5 commented 5 years ago

Hello etingof and thanks for your response. Here is the code :


from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData('public'),
           UdpTransportTarget(('192.168.8.197', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('.1.3.6.1.2.1.2.2.1.12.2')),
    )
)

if errorIndication:
    print(errorIndication)
elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
                        errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))
~]$ time python2 sk001.py 
SNMPv2-SMI::mib-2.2.2.1.12.2 = 23517

real    0m0.733s
user    0m0.601s
sys 0m0.143s

~]$ time python3 sk001.py 
SNMPv2-SMI::mib-2.2.2.1.12.2 = 23518

real    0m5.579s
user    0m1.727s
sys 0m3.878s

i have tried this code on two FreeBSD machines with python3.7 and 3.6 on both there is big delay . Any idea how to debug ?


dont't know if this will help but here is part of my trace

lstat("/usr/local/bin/python3.7",{ mode=-rwxr-xr-x ,inode=634929,size=11563488,blksize=131072 }) = 0 (0x0) pipe2(0x7fffffff48d8,O_CLOEXEC) = 0 (0x0) fstat(4,{ mode=p--------- ,inode=1,size=0,blksize=4096 }) = 0 (0x0) ioctl(4,TIOCGETA,0x7fffffff4720) ERR#25 'Inappropriate ioctl for device' lseek(4,0x0,SEEK_CUR) ERR#29 'Illegal seek' pipe2(0x7fffffff47d8,O_CLOEXEC) = 0 (0x0) sigprocmask(SIG_BLOCK,{ SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGTRAP|SIGABRT|SIGEMT|SIGFPE|SIGKILL|SIGBUS|SIGSEGV|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2 },{ }) = 0 (0x0) fork() = 50426 (0xc4fa) sigprocmask(SIG_SETMASK,{ },0x0) = 0 (0x0) close(7) = 0 (0x0) close(5) = 0 (0x0) read(6,0x8054d22e0,50000) = 0 (0x0) close(6) = 0 (0x0) lseek(4,0x0,SEEK_CUR) ERR#29 'Illegal seek' fstat(4,{ mode=p--------- ,inode=1,size=0,blksize=4096 }) = 0 (0x0) read(4,"/usr/local/bin/python3.7: ELF 64"...,8192) = 182 (0xb6) read(4,0x801a728d6,8010) = 0 (0x0) close(4) = 0 (0x0) wait4(50426,{ EXITED,val=0 },0x0,0x0) = 50426 (0xc4fa) openat(AT_FDCWD,"/usr/local/lib/python3.7/site-packages/Cryptodome/Util/../Cipher/_raw_ecb.cpython-37m.so",O_RDONLY|O_CLOEXEC|O_VERIFY,00) ERR#2 'No such file or directory' lstat("/usr/local/bin/python3",{ mode=lrwxr-xr-x ,inode=642289,size=9,blksize=131072 }) = 0 (0x0) readlink("/usr/local/bin/python3","python3.7",1024) = 9 (0x9) lstat("/usr/local/bin/python3.7",{ mode=-rwxr-xr-x ,inode=634929,size=11563488,blksize=131072 }) = 0 (0x0) pipe2(0x7fffffff48d8,O_CLOEXEC) = 0 (0x0) fstat(4,{ mode=p--------- ,inode=1,size=0,blksize=4096 }) = 0 (0x0) ioctl(4,TIOCGETA,0x7fffffff4720) ERR#25 'Inappropriate ioctl for device' lseek(4,0x0,SEEK_CUR) ERR#29 'Illegal seek' pipe2(0x7fffffff47d8,O_CLOEXEC) = 0 (0x0)

there are a lot of ERR#25 'Inappropriate ioctl for device' lseek(4,0x0,SEEK_CUR) ERR#29 'Illegal seek' errors in the trace. Also i forgot to mention my file system is zfs ..

edit: I tried another FreeBSD 12 with precompiled python 3.7 and last pysnmp ... same delay

lextm commented 2 months ago

Recent releases have dropped Python 3.7 support. Besides, the percentage of FreeBSD out there is too low to make it worthwhile.

As the new maintainer of this project, we have no plan to investigate any FreeBSD issues.