Forum Discussion
David_Remington
Employee
Mar 13, 2008dilemma: run slow or crash on load
So I have a rule I am writing that has to parse a very large (6000+) entry class file for every URI that traverses the virtual server. Because of the constraints on possibilities for a match I basical...
spark_86682
Mar 20, 2008Historic F5 Account
Basically, you're doing this in a very inefficient way. Specifically, you're converting your class list into an array by iterating over your class list 1,296 (=36*36) times. You can do the same thing by only iterating over it once:
when RULE_INIT {
set debug 1
if { $debug > 0 } {log local0.notice "rule initializing"}
set list_map [lsort -unique -decreasing -ascii $::cl_map_v10]
array unset ::map
array unset ::listsize
if { $debug > 0 } {log local0.notice "starting to load array"}
foreach element $list_map {
set idx1 [string index $element 1]
set idx2 [string index $element 2]
set count 1
catch { set count $::listsize(${idx1}${idx2}) }
set ::map(${idx1}${idx2},${count}) $element
incr count
set ::listsize(${idx1}${idx2}) $count
}
if { $debug > 0 } {log local0.notice "map(ab,1): $::map(ab,1)"}
if { $debug > 0 } {log local0.notice "done load array"}
if { $debug > 0 } {log local0.notice "rule initialized"}
}
This code takes the fist two characters of each element of your class, looks up which index into the "map" array is the next one, stuffs it in there, and increments and stores the new count for that index. The "catch" line is just a clever way of dealing with the fact that if you try to access an unset array key, Tcl gives an error instead of returning 0 or something. So if we haven't set a particular "listsize" key yet, the "count" variable keeps its value of 1.
A few other notes: I've made your "array set"s into "array unset"s, since I think that that's what you really meant to do. I got rid of "keylist" since you never actually use it. I did not check if the values stored in "listsize" match your original rule, or are off by 1. If they are off, I think you can just do "set count 0" instead of 1, and move the "incr count" line just after the "catch" line. Basically, this should get you close, and you can make further changes to suit your application.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects