Re: Efficient sorting of SNMP oids
AV == Avleen Vig avl...@gmail.com writes: AV On Oct 31, 2009, at 22:17, Dave Hodgkinson daveh...@gmail.com wrote: Then build it in to your own dist tree. AV Or better yet, extract the key functionality you need from the module AV and mak it part of your script! Easy. and one more idea. sort::maker actually generates source code for its sorts and you can print that out. then you cut/paste that generated code into your program. the only issue i see is how to handle varying length OIDs. but i leave that as an exercise to the reader. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com -
Re: Efficient sorting of SNMP oids
On Oct 31, 2009, at 15:17, Dave Hodgkinson wrote: Using Sort::Key::OID or sort::maker would have been great, except that we need to deploy the script to a rather large number of servers and it is traditionally long and painful to get modules approved and deployed in our machines. Then build it in to your own dist tree. Yeah; that's what we do. We have a git submodule (cpan/) with our application, so when we upgrade or install a module it gets branched/ merged/tracked/code-reviewed/managed just like any other application change we make. We have a helper script[1] that starts the CPAN shell with INSTALL_BASE appropriately configured to make it easy. - ask [1] http://git.develooper.com/?p=combust.git;a=blob;f=bin/cbcpan;h=b69b81829e43450344f9dc35349151cf2750e6b5;hb=HEAD
Re: Efficient sorting of SNMP oids
On Sat, Oct 31, 2009 at 04:03:15PM +, B Maqueira wrote: Dear all, I need to sort eficiently a large array (~9000) of SNMP OIDs. I am currently trying the following code: my @sorted_oids = map { $_-[0] } sort { $a-[1] cmp $b-[1] } map { [$_, pack('w*', split(/\./, $_))] } @oids; But this fails since it outputs 1.3.6.1.4.1.2333.3.2.61001.1.10 before than 1.3.6.1.4.1.2333.3.2.8080.1.1.1 Any ideas? http://search.cpan.org/~salva/Sort-Key-OID-0.05/ looks like the ticket... \Anton. -- Matters of elegance ought to be left to the tailor and to the cobbler. -- L. Boltzmann
Re: Efficient sorting of SNMP oids
BM == B Maqueira b...@ferrarihaines.com writes: BM Dear all, BM I need to sort eficiently a large array (~9000) of SNMP OIDs. BM I am currently trying the following code: BM my @sorted_oids = map { $_-[0] } BM sort { $a-[1] cmp $b-[1] } BM map { [$_, pack('w*', split(/\./, BM $_))] } @oids; BM But this fails since it outputs 1.3.6.1.4.1.2333.3.2.61001.1.10 before BM than 1.3.6.1.4.1.2333.3.2.8080.1.1.1 sort::maker could do that and generate a faster sort with the GRT. just generate an array of integers (or shorts) and pack them for the key. similar to what you have there. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com -
Re: Efficient sorting of SNMP oids
RF == Richard Foley richard.fo...@rfi.net writes: RF Should that be a numerical sort via the spaceship operator? RF = instead of cmp nope, since he is trying to compare a long string of the packed OIDs. you can't compare woth = anything other than normal integers or floats. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com -
Re: Efficient sorting of SNMP oids
On 31 Oct 2009, at 16:03, B Maqueira wrote: I need to sort eficiently a large array (~9000) of SNMP OIDs. I am currently trying the following code: my @sorted_oids = map { $_-[0] } sort { $a-[1] cmp $b-[1] } map { [$_, pack('w*', split(/\./, $_))] } @oids; But this fails since it outputs 1.3.6.1.4.1.2333.3.2.61001.1.10 before than 1.3.6.1.4.1.2333.3.2.8080.1.1.1 Any ideas? That's because w format is a BER encoding, and this does not map integers into strings such that ordering is maintained. For example, 16383 encodes to \xff\x7f, but 16384 encodes to \x81\x80\x00 which string-sorts earlier. Relatively few encodings *do* maintain that ordering. Big-endian fixed- width does. So I'd use N* instead in your pack format, mainly because I'm not entirely sure whether the components of SNMP OIDs can ever be greater than 65535 and thus whether I could thus get away with n* to halve the storage required.
Re: Efficient sorting of SNMP oids
On 31 Oct 2009, at 16:03, B Maqueira wrote: Dear all, I need to sort eficiently a large array (~9000) of SNMP OIDs. I am currently trying the following code: my @sorted_oids = map { $_-[0] } sort { $a-[1] cmp $b-[1] } map { [$_, pack('w*', split(/\./, $_))] } @oids; But this fails since it outputs 1.3.6.1.4.1.2333.3.2.61001.1.10 before than 1.3.6.1.4.1.2333.3.2.8080.1.1.1 Any ideas? Convert them to 256 bit (or whatver integers), sort and convert back? :) -- Dave HodgkinsonMSN: daveh...@hotmail.com Site: http://www.davehodgkinson.com UK: +44 7768 490620 Blog: http://www.davehodgkinson.com/blog Photos: http://www.flickr.com/photos/davehodg
Re: Efficient sorting of SNMP oids
Peter Corlett wrote: On 31 Oct 2009, at 16:03, B Maqueira wrote: I need to sort eficiently a large array (~9000) of SNMP OIDs. I am currently trying the following code: my @sorted_oids = map { $_-[0] } sort { $a-[1] cmp $b-[1] } map { [$_, pack('w*', split(/\./, $_))] } @oids; But this fails since it outputs 1.3.6.1.4.1.2333.3.2.61001.1.10 before than 1.3.6.1.4.1.2333.3.2.8080.1.1.1 Any ideas? That's because w format is a BER encoding, and this does not map integers into strings such that ordering is maintained. For example, 16383 encodes to \xff\x7f, but 16384 encodes to \x81\x80\x00 which string-sorts earlier. Relatively few encodings *do* maintain that ordering. Big-endian fixed-width does. So I'd use N* instead in your pack format, mainly because I'm not entirely sure whether the components of SNMP OIDs can ever be greater than 65535 and thus whether I could thus get away with n* to halve the storage required. Thank you all for the advice. Using Sort::Key::OID or sort::maker would have been great, except that we need to deploy the script to a rather large number of servers and it is traditionally long and painful to get modules approved and deployed in our machines. Using N* certainly did the trick. I guess I must read the RFC for OIDs + work out what is the range covered using N*. But right now I have some oids looking like BASE.8129.1.10.1402551989 and BASE.61003.1.10.2138245292 that seem to be working fine. Again, huge thanks to you all for your replies!
Re: Efficient sorting of SNMP oids
On 31 Oct 2009, at 20:56, B Maqueira wrote: Using Sort::Key::OID or sort::maker would have been great, except that we need to deploy the script to a rather large number of servers and it is traditionally long and painful to get modules approved and deployed in our machines. Then build it in to your own dist tree. -- Dave HodgkinsonMSN: daveh...@hotmail.com Site: http://www.davehodgkinson.com UK: +44 7768 490620 Blog: http://www.davehodgkinson.com/blog Photos: http://www.flickr.com/photos/davehodg
Re: Efficient sorting of SNMP oids
2009/11/1 Avleen Vig avl...@gmail.com: On Oct 31, 2009, at 22:17, Dave Hodgkinson daveh...@gmail.com wrote: On 31 Oct 2009, at 20:56, B Maqueira wrote: Using Sort::Key::OID or sort::maker would have been great, except that we need to deploy the script to a rather large number of servers and it is traditionally long and painful to get modules approved and deployed in our machines. Then build it in to your own dist tree. Or better yet, extract the key functionality you need from the module and mak it part of your script! Easy. That's what I was going to suggest. Behold the power of open source, etc. Cheers, Philip -- Philip Newton philip.new...@gmail.com