People ask me from time to time whether they can expect a performance gain from moving to Saxon-SA. The answer is: it depends!
The Xmark benchmark is a case in point. It's not a very satisfactory benchmark in many ways, because the queries are very "relational" in style, but there are some people with that kind of workload and so long as one accepts that it's not typical of every kind of workload, it's not a bad test.
Here's how Saxon-B and Saxon-SA compare for the twenty queries in the test suite. This is version 8.7.1 (not yet released), running against a 10Mb data file, with timings in milliseconds.
Query Saxon-SA Saxon-B
1 8 6
2 6 6
3 25 22
4 24 21
5 8 8
6 4 4
7 32 31
8 38 11196
9 50 14023
10 104 1435
11 13686 13005
12 4296 3335
13 3 3
14 120 116
15 4 4
16 8 8
17 11 11
18 13 13
19 66 66
20 38 38
What do these numbers tell us? Firstly, the difference between 8ms and 6ms simply isn't statistically significant. So for 15 out of these 20 tests, the performance under Saxon-SA is essentially identical to that under Saxon-B. Then there are three tests (Q8, Q9, and Q10) where the performance under Saxon-SA is dramatically better (and the bigger the data file, the bigger the difference becomes. This is where the Saxon-SA optimizer has found a better strategy for evaluating a join.
If we look at one of these queries Q8, it's like this:
(: Q8. List the names of persons and the number of items they bought.
-- (joins person, closed\_auction)} :)
for $p in (:document("auction.xml"):)/site/people/person
let $a := for $t in (:document("auction.xml"):)/site/closed_auctions/closed_auction
where $t/buyer/@person = $p/@id
return $t
return <item person="{$p/name}"> {count ($a)} </item>
The important thing is that "where" condition relating the two range variables $t and $p, both of which are defined in a "for" expression. Saxon-B here does two nested loops, testing each ($t, $p) pair to see if the condition is satisfied. Saxon-SA, by contrast, decides to build a hash index which avoids having to loop over all the $t items once for every $p.
There are two join queries in the collection where Saxon-SA didn't make any difference, in fact things got slightly worse: Q11 and Q12.
In Q11 and Q12, the join condition is
where $p/profile/@income > (5000 * $i)
and Saxon at present isn't doing any optimization for non-equijoins (joins where the operator isn't "=" or "eq"). At present I don't know why Saxon-SA is performing worse for these two queries: it's not a major difference, but it's sufficiently significant to be worth investigating.
The bottom line is: most queries probably run at about the same speed with Saxon-B and Saxon-SA. A few queries run dramatically faster with Saxon-SA.
|
|
||||||||
|
Login
|
Join optimization
Comments
Re: Join optimization
I've established why the two ">" join queries are running slightly slower in Saxon-SA. It's because, paradoxically, Saxon-B sometimes has better type information available than Saxon-SA. Given this path expression
for $i in /site/open_auctions/open_auction/initial Saxon-B knows that the result of atomizing $i will be untyped atomic, and therefore (5000*$i) will be an xs:double, and therefore that in the expression $p/profile/@income > (5000 * $i), the left-hand operand will have to be converted to double and the comparison will be between two doubles. Saxon-SA, in the absence of a schema, doesn't know what types the nodes will be, and has to allow for the possibility that this expression is testing values of type duration. So it has to do more of the work at run-time. If there's a moral to this tale, it's that Saxon-SA works best when there's a schema! In fact, if there isn't a schema, you can get the same behavior as Saxon-B by setting configuration.setAllNodesUntyped(true), which should redress the performance difference. Re: Join optimization
Life is always a bit more complicated than you think. Setting configuration.setAllNodesUntyped(true) made a big difference to Q11, improving the run time from 13686ms to 10515ms, which is considerably better than the Saxon-B figure. But the run time for Q12 has increased, from 4296ms to 4837ms. Tantalizing.
But before I can investigate any further, I'm off to hear Mozart's C Minor Mass at Reading Great Hall. That should take my mind off the problem if anything will. Re: Join optimization
This is slightly off topic, but related to how Saxon-SA and Saxon-B handle large files. From my testing, Saxon-B is limited to working with XML files in the range of 100 MB. Anything much over that size Saxon-B will choke with a Java out of memory error. Since I'm typically working with XML files in the range of 500 MB to 900 MB size I have found Saxon-B to not be up to the task. Does anyone know whether Saxon-SA will process large XML datasets in the 500 MB to 900 MB size range.
Re: Re: Join optimization
For handling large files, you might find that the "serial processing" optimization meets your needs: see http://www.saxonica.com/documentation/sourcedocs/serial.html
There's no intrinsic limit to file sizes in Saxon but I usually recommend allocating 5Mb of memory per Mb of source file. Re: Join optimization
by
Makoto Yui
on Sat 19 Aug 2006 11:35 BST | Permanent Link
Is the "join" optimization available in saxon-sa8.7.3j? With my test of XMark Q8 queries against 11M dataset, only slight difference appears between saxon-sa and saxon-sb. Both of them requires about 8 seconds for execution. Are some additional instructions needed for the optimization?
Re: Re: Join optimization
by
Makoto Yui
on Sat 19 Aug 2006 11:54 BST | Permanent Link
Ah.., I noticed that (evaluation) license might be required.
Re: Re: Re: Join optimization
As well as using the saxon8sa.jar file, you need to select schema-aware processing using the -sa option (or use the com.saxonica.Query entry point). This will only work if you have a license key installed.
Re: Re: Re: Re: Join optimization
by
Makoto YUI
on Sat 19 Aug 2006 17:43 BST | Permanent Link
works fine(?). xmark Q8 query run around 1.5 sec.
thax. #BTW, Q9 query seems to be not (join) optimized. Is there reason? Re: Re: Re: Re: Re: Join optimization
Q9 certainly benefits from join optimization in my runs. Perhaps there's more than one version of the benchmark, I'm not sure. It would probably be best to raise this on the saxon-help list or forum. Give the code of the query you're running and the timings under Saxon-B and Saxon-SA.
Re: Re: Re: Re: Re: Re: Join optimization
by
Makoto YUI
on Sat 19 Aug 2006 20:44 BST | Permanent Link
I see. I'll post to the ML for the next time.
# Officially provided queries are used for my Saxon-*SA* evaluation without any modification. # http://www.ins.cwi.nl/projects/xmark/Assets/xmlquery.txt Re: Re: Re: Re: Re: Re: Re: Join optimization
Thanks. This is indeed different from the version which I'm using, which I cited in a remark here: http://www.stylusstudio.com/xquerytalk/200604/001346.html
I see that the original is even more cumbersomely expressed. I don't know where my version came from, I'm afraid. Whoever wrote these queries was having a bad day, or else they had a twisted mind. Re[6]: Join optimization
I've now fixed the optimizer so it picks up the join condition in the original version of Q9. It was a typical optimizer glitch - the pattern that it recognizes as suitable for indexing wasn't present in the query at the time it was looking for it, it only became present later as a result of a further rewrite.
Re: Re[6]: Join optimization
by
Makoto YUI
on Sun 20 Aug 2006 17:35 BST | Permanent Link
thanks fixing.
# I don't think XMark queries are everything, but it is important for fairly comparing implementations. |
Search
Recent Comments
Month Archive
|
||||||