473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Speed of pysnmp

There's been some talk recently about the relative speeds of the various
python SNMP libraries. I just did a little benchmarking, and got some
surprising results.

I downloaded pysnmp-3.4.2 and build a little mib walk application around
it. I used it to walk ifDescr on an Extreme Summit 48i (48 port
ethernet switch). I did the same thing using snmpwalk from net-snmp
5.0.8.

The switch is back in my office; I'm sitting at home running this on my
Mac OSX box, through a VLAN connection over DSL. Ping times are around
40ms:

--- 192.168.1.1 ping statistics ---
13 packets transmitted, 13 packets received, 0% packet loss
round-trip min/avg/max = 37.597/39.801/41.902 ms

The results are rather surprising (I ran these several times; the
numbers below are fairly typical):

$ time ./get.py > get.out
real 0m9.045s
user 0m1.010s
sys 0m0.510s

$ time snmpwalk -v1 -c public 192.168.1.1 ifDescr > snmpwalk.out
real 0m3.896s
user 0m0.120s
sys 0m0.130s

The two output files had identical information (except for trivial
output formatting differences). There were a total of 73 rows.

It's entirely expected that the pysnmp version had much higher CPU times
(from about 0.25 to 1.5 total user+sys). What I don't understand is why
the real time went up so much, from about 4 seconds to about 9 seconds.
Most of the time doing a mib walk is waiting for UDP packets on the wire.

If the ping RTT is 40ms, and there's 73 rows, that's 2.9 seconds, which
accounts for about 3/4 of the real time. Add in a 1/4 second of CPU at
this end, figure the same at the other end, a few ms for process
switching for each packet, and it's easy to see where all the time goes.

But, where does the additional 5 seconds of real time come from for the
pysnmp version? I burned another 1-1/4 seconds of CPU at my end, but
everything else really should be the same. The network doesn't know
what kind of code built the packets. Neither does the box at the other
end. Something's inserting another 50ms or so delay per packet which is
not accounted for my the CPU time. Anybody have any ideas where that
might be coming from?
Jul 18 '05 #1
4 5385
On Sat, 10 Jul 2004 20:04:27 -0400, Roy Smith <ro*@panix.com> wrote:
There's been some talk recently about the relative speeds of the various
python SNMP libraries. I just did a little benchmarking, and got some
surprising results.

I downloaded pysnmp-3.4.2 and build a little mib walk application around
it. I used it to walk ifDescr on an Extreme Summit 48i (48 port
ethernet switch). I did the same thing using snmpwalk from net-snmp
5.0.8. [snip] But, where does the additional 5 seconds of real time come from for the
pysnmp version? I burned another 1-1/4 seconds of CPU at my end, but
everything else really should be the same. The network doesn't know
what kind of code built the packets. Neither does the box at the other
end. Something's inserting another 50ms or so delay per packet which is
not accounted for my the CPU time. Anybody have any ideas where that
might be coming from?
Try profiling the pysnmp code, see where the time is being taken.
From past, bitter experience, I can say that you can make a massive

massive difference in any SNMP application by carefully constructing
your getnext packets - don't just get things one at a time. Do some
rough calculations on how many entries you can fit in a packet, and
getnext multiple things at once. If you're walking a table of more than
one column, start at the top of each column and getnext in parallel.
If it's just one column, hopefully you can find out how many entries
are in the table. Start off at 0, 25%, 50% and 75% of the table, and
walk it in parallel. The SnmpTable code in the (very old, and now
abandoned) snmpy package had all sorts of evil smarts for dealing
with this stuff. I believe it got ported across to pysnmp, but I've been
blissfully able to avoid SNMP for about 5 years now, so I haven't
touched it at all.
Jul 18 '05 #2
Roy Smith <ro*@panix.com> wrote:

[ skipped ]
It's entirely expected that the pysnmp version had much higher CPU times
(from about 0.25 to 1.5 total user+sys). What I don't understand is why
the real time went up so much, from about 4 seconds to about 9 seconds.
Most of the time doing a mib walk is waiting for UDP packets on the wire.


My guess is that Python code takes up so much CPU time on a single SNMP message
processing, that OS's likely to schedule out (involuntarily context switch) python
process for greater number of times than it is with C version.

In other words, if you burn 0.01 CPU sec, you're likely to get it done within a
process's time slice. Although, when you burn 10 CPU secs in bulk, you're likely
to 1) run out of process's time slice (context switch) 2) compete for CPU time
with other processes on the system. In the end, both factors might contribute
to real time increase...

-ilya
Jul 18 '05 #3
Anthony Baxter <an***********@gmail.com> wrote:

[ skipped ]
From past, bitter experience, I can say that you can make a massive

massive difference in any SNMP application by carefully constructing
your getnext packets - don't just get things one at a time. Do some
rough calculations on how many entries you can fit in a packet, and
getnext multiple things at once. If you're walking a table of more than
one column, start at the top of each column and getnext in parallel.


[ skipped ]

A variation of this method would be to use GETBULK PDU of SNMP v2c
wnenever available at your management target to save on 1) round-trip time
2) SNMP message build/parse expenses. Here's what I got doing IF-MIB table
traversal:

# pysnmp
[ilya@cray ~]$ /usr/bin/time pysnmpbulkwalk wrt -c public .1.3.6.1.2.1.2.2.1.1 > /dev/null
1.13user 0.02system 0:01.35elapsed 84%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (667major+409minor)pagefaults 0swaps

[ilya@cray ~]$ /usr/bin/time pysnmpwalk wrt -c public .1.3.6.1.2.1.2.2.1.1 > /dev/null
2.39user 0.04system 0:05.93elapsed 40%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (667major+368minor)pagefaults 0swaps

# net-snmp
[ilya@cray ~]$ /usr/bin/time snmpbulkwalk -On -v2c -c public wrt .1.3.6.1.2.1.2.2.1.1 > /dev/null
0.07user 0.02system 0:00.50elapsed 17%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (404major+125minor)pagefaults 0swaps

[ilya@cray ~]$ /usr/bin/time snmpwalk -On -v1 -c public wrt .1.3.6.1.2.1.2.2.1.1 > /dev/null
0.06user 0.01system 0:02.68elapsed 2%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (404major+122minor)pagefaults 0swaps

-ilya
Jul 18 '05 #4
In article <cd**********@news.rol.ru>, Ilya Etingof <il**@glas.net>
wrote:
Roy Smith <ro*@panix.com> wrote:

[ skipped ]
It's entirely expected that the pysnmp version had much higher CPU times
(from about 0.25 to 1.5 total user+sys). What I don't understand is why
the real time went up so much, from about 4 seconds to about 9 seconds.
Most of the time doing a mib walk is waiting for UDP packets on the wire.


My guess is that Python code takes up so much CPU time on a single SNMP
message
processing, that OS's likely to schedule out (involuntarily context switch)
python
process for greater number of times than it is with C version.

In other words, if you burn 0.01 CPU sec, you're likely to get it done within
a
process's time slice. Although, when you burn 10 CPU secs in bulk, you're
likely
to 1) run out of process's time slice (context switch) 2) compete for CPU
time
with other processes on the system. In the end, both factors might contribute
to real time increase...

-ilya


It turned out to be less complicated than that. In fact, it turned out
to be so simple that I canceled my articled about 2 minutes after I
posted it, but I guess it escaped before I got to it!

The problem turned out that in my python code, I was doing a getNext to
get the next oid, then a get for the value of that oid, so I was
generating twice as many packets as I needed to!

Why was I doing such a dumb thing? Because I was using a style I had
gotten used to in another system I'd worked with which caches the values
of getNext's. My code didn't have the cache, so I went out to the
network to satisfy the second request. Dumb, dumb, dumb.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Yang Li Ke | last post by:
Hi guys, Is it possible to know the internet speed of the visitors with php? Thanx -- Yang
3
by: WIWA | last post by:
I have recently installed pySNMP 3.3.2 and use Python 2.2.2. Thanks to Peter Hansen, I succeeded to install pySNMP properly. I'm not completely new to SNMP (I know the basics), but I'm new to...
0
by: WIWA | last post by:
Hi, I have installed pySNMP. I want to make an application where I read out all the OIDs of a MIB of a particular device. In other words, I want to do an SNMPwalk for a certain MIB. I can do...
34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
2
by: Axel Scheepers | last post by:
Hi All, Python is so great. I've been creating a small set of objects to get some stats from our adsl routers. So far it works great and fast. However, in the shell script I created over a year...
7
by: YAZ | last post by:
Hello, I have a dll which do some number crunching. Performances (execution speed) are very important in my application. I use VC6 to compile the DLL. A friend of mine told me that in Visual...
3
by: rob.audenaerde | last post by:
I'm trying to monitor about 250 devices with SNMP, using PySNMP version 4. I use the threading.Thread to create a threadpool of 10 threads, so devices not responding won't slow down the monitoring...
6
by: Jassim Rahma | last post by:
I want to detect the internet speed using C# to show the user on what speed he's connecting to internet?
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.