How do I avoid expensive XPaths that slow down my console and Gateway
Xpaths which are deemed to be common (used a lot) have optimized code paths, which where at all possible should be used over and above non-optimized paths Which is all fine, but what constitute slow paths, and which are fast? Every time a change of state occurs in the gateway (value change, items added and removed, snooze or active status changing, DB logging being modified, user assignment and so on) an event is sent which must be processed. Even in small gateways, this could be thousands a minute or even second. Pretty much all the paths need to be reviewed to see if there is something that needs to be done for a specific event, so one expensive path can have a massive detrimental effect on the gateway / console / montage and so on. Here are some general guidelines about what is fast and what is slow during XPath evaluation: Fast Paths
- Fully qualified, each with a name down to the target item, generally these paths have the capacity to match 0..1 items, For example
- /geneos/gateway[(@name=“Helpdesk Ticket Flow”)]/directory/probe[(@name=“iwhddb2_hdflow”)]/managedEntity[(@name=“Estimate Evaluation”)]/sampler[(@name=“Estimates NOT IN -1 to 1”)][(@type="")]/dataview[(@name=“Estimates NOT IN -1 to 1”)]/rows/row[(@name=“38240”)]/cell[(@column=“ID”)]
- Managed Entity Elements,are fast to resolve, if you can filter the path for part of the system ‘/geneos/gateway/directory/probe/managedEntity[(attr(“Application”)=“functions”)]’ then they will be faster Slow Paths:
- Use of relative components are considered rarer, and are not optimized, so if possible avoid //, ancestor::, .. , etc. a path like ‘//managedEntity’ is much slower than the equivalent ‘/geneos/gateway/directory/probe/managedEntity’
- Wildcards are expensive, for example ‘/geneos/gateway/directory/probe/managedEntity[wild(@name,“foo*”)]’, if they can be avoided its recommended.
- Path variables, Path variable resolution causes slow down, they should be used only where required. Sometimes they are used to get around the restriction whereby relative paths cannot end up matching multiple columns, but this almost always causes a slow down. Tricks of the trade:
- Use filters further up the path, If you are search for all red cells, and you use a path like //cell*[(@severity=3)]* then it needs to look at all severity changes on cells across the system, the system, you can add a filter to restrict the number of items that needs to be review with a path like ‘/geneos/gateway/directory/probe/managedEntity[(state(“severity”)=“3”)]/sampler/dataview//cell[(state(“severity”)=“3”)]’ - note the use of the Severity = 3 in the Entity element. Xpath Extras - Quick Reference Guide - explains in more detail how to build Xpaths.