XML Processing Measurements using XPB4J


Author: Pankaj Kumar
e-mail: pankaj_kumar@acm.org
Date: September 30, 2001

Mesurement Environment

The measurements were taken on a PentiumII ( 350MHz ) machine with 128MB of SDRAM running Windows98.

Software environment consisted of:

Certain other versions of these software were also used for comparison as reported under Conclusions from Mesurements.

Measurement Process

For the measurements, loopCount was set to 10 and gcFlag was set to true in file args.xml. This roughly translates into following loop for measurements:
      // Code for illustration only. Won't compile.
      for (int i = 0; i < loopCount; i++)
        {
        System.gc();
        long startMem = Runtime.totalMemory() - Runtime.freeMemory();
        long startTime = System.currentTimeMillis();
        result = process();	// Do the processing.
        long endTime = System.currentTimeMillis();
        long endMem = Runtime.totalMemory() - Runtime.freeMemory();
        memUsed[i] = endMem - startMem;
        elapsedTime[i] = endTime - startTime;
        }

Both Crimson and Xerces parsers were used for the measurement. To use Crimson parser, crimson.jar was kept in .\lib directory. Similarly, to use Xerces parser, xerces.jar was kept in .\lib directory. Note that the run.bat, used for kicking-off the execution run, took jar files from .\lib.

Following precautions were taken while making the measurements:

  1. No other activity was happening on the machine.
  2. Only one processing method was enabled in file args.xml for each execution run to ensure warmup for each processing method.
  3. Multiple execution runs were observed to ensure consistency of measurement figures.

Input Data

Input data for the measurements were obtained by running batch file rxgen.bat to generate random XML files. This program takes a number as an argument and generates a somewhat random XML document. Look at the source file org\xperf\xpb\RandXMLGen.java ( included in the distribution ) to understand how the input file is generated.

Five different input files, labelled as TINY, SMALL, MEDIUM, BIG and HUGE, were used. Their characteristics are shown in the table below:

Labelrxgen arg.Filesize
TINY209KB
SMALL20072KB
MEDIUM2000719KB
BIG200007.18KB
HUGE20000071.6MB

You can generate a MEDIUM input file by issuing:

       >rxgen 2000
By default, the generated file is named rxgen.xml and is placed in Data subdirectory.

Note: There could be slight variation in size of the generated file everytime rxgen is run, even if the argument remains same.

Mesurements

XML File Size Processing API Parser Crimson: 1.1.1beta2 Parser Xerces: 2.0.2beta2
1st Iteration
(in milli secs.)
Average
(in milli secs.)
Memory Usage
(in KB)
1st Iteration
(in milli secs.)
Average
(in milli secs.)
Memory Usage
(in KB)
TINY
rxgen 20
9KB
SAX 5024101 502437
DOM 32036142 44034128
PULL 28024104 27024104
JDOM 27047162 28044135
XSLT 2030147463 2140146390
COCOON DIDN'T WORK WITH CRIMSON 3790248848
SMALL
rxgen 200
72KB
SAX 22058172 2807486
DOM 55091385 610121446
PULL 50080746 49080746
JDOM 600111518 660126523
XSLT 2860352562 2910328905
COCOON DIDN'T WORK WITH CRIMSON 4010323880
MEDIUM
rxgen 2000
719KB
SAX 660310279 830367411
DOM 14206042897 18107812842
PULL 12106101244 12005731819
JDOM 19308603177 20309452801
XSLT 566024772529 604024342535
COCOON DIDN'T WORK WITH CRIMSON 58301254900
BIG
rxgen 20000
7197KB
SAX 33502946352 42903570450
DOM 8350596826.5MB 10600703025MB
PULL 588051431496 598052701526
JDOM 187901601326.9MB 227401735025MB
XSLT 434003883022780 434403817021596
COCOON DIDN'T WORK WITH CRIMSON 1675010257845
HUGE
rxgen 200000
716MB
SAX 2933028610378 3729036140470
DOM OUT OF MEMORY OUT OF MEMORY
PULL 52020528401861 54320514101841
JDOM OUT OF MEMORY OUT OF MEMORY
XSLT OUT OF MEMORY OUT OF MEMORY
COCOON DIDN'T WORK WITH CRIMSON OUT OF MEMORY

Conclusions from Measurements

Careful analysis of the measurement figures under Mesurements and with few additional experimentation, a number of inferences can be made.

Note: The following conclusions are valid only for XStat processing under the specified Mesurement Environment. Care must be taken to apply these results to other situations.

  1. SAX Processing is faster than DOM processing and uses much less memory. The table below shows the average processing time and memory used with SAX and DOM processing using Crimson parser.

    Input SizeProcessing TimeMemory Used
    SAXDOMSAXDOM
    TINY24ms36ms101KB142KB
    SMALL58ms91ms172KB385KB
    MEDIUM310ms604ms279KB2.90MB
    BIG2.95s5.97s352KB26.5MB

    Interestingly, the method of measurement favours the DOM processing as the garbage collection is forced outside the measurement window. As DOM processing uses more memory objects, more time will be spent in garbage collection. So, in a real scenario, the DOM processing will have much worse performance than SAX.

    Not surprisingly, the amount of memory used by SAX processing remains almost constant with input size whereas the memory used DOM processing increases in proportion to the input size. This could be a real problem for applications that are going to deal with large input or multiples of them simultaneously. DOM just won't scale.

    The slight increase in memory for SAX processing with increase in input size is attributed to the memory objects holding the processing results and other bookkeeping info.

  2. Crimson is faster than Xerces and uses less memory. The table below shows the average processing time and memory used with SAX processing using Crimson and Xerces parser.

    Input SizeProcessing TimeMemory Used
    CrimsonXercesCrimsonXerces
    TINY24ms24ms101KB37KB
    SMALL58ms74ms172KB86KB
    MEDIUM310ms367ms279KB411KB
    BIG2.95s3.57s352KB450KB
    HUGE28.6s36.1s378KB470KB

    Note that the difference in processing speed is insignificant at small input size but is quite pronounced at very large input size. Another curious thing to note is that Xerces uses less memory for smaller inputs. Both these facts together could mean better performance with Xerces at moderate input size ( < 50 KB ).

  3. Pull Parser API is slower than SAX and uses significantly more memory. The table below shows the average processing time and memory used with SAX and Pull Parser processing using Crimson parser.

    Input SizeProcessing TimeMemory Used
    SAXPULLSAXPULL
    TINY24ms24ms101KB104KB
    SMALL58ms80ms172KB746KB
    MEDIUM310ms610ms279KB1.24MB
    BIG2.95s5.14s352KB1.50MB
    HUGE28.6s52.84s378KB1.86MB

    This is hard to explain in theory as the Pull Parsing perhaps couldn't be more expensive. One practical explanation could be that the Pull Parser API is meant to be only peeking into first few elements and hence is not optimized for full document scan ( yet !).

  4. XStat processing using XSLT is slowest and most demanding on RAM. The table below compares the average processing time and memory usage of XSLT method with SAX method.

    Input SizeProcessing TimeMemory Used
    SAXXSLTSAXXSLT
    TINY24ms147ms101KB463KB
    SMALL58ms352ms172KB562KB
    MEDIUM310ms2.47ms279KB2.53MB
    BIG2.95s38.83s352KB22.7MB
    HUGE28.6sNA378KBNA

    It appears that the transformer loads the whole document in memory. This certainly is not required for XStat processing..

    Note: It might be possible to write XSL stylesheet in a way that avoids loading of whole document. If you know any such way, please do let me know.

  5. JDOM is slower than DOM. This is obvious from the following table.

    Input SizeProcessing TimeMemory Used
    JDOMDOMJDOMDOM
    TINY47ms36ms162KB142KB
    SMALL111ms91ms518KB385KB
    MEDIUM860ms604ms3.17KB2.90MB
    BIG16.0s5.97s26.9MB26.5MB

    One might think that JDOM would be better at runtime and memory usage efficiency as it uses native Java classes. In reality, it compares poorly with DOM. But may be because JDOM software is still in beta and necessary optimizations haven't been carried out.

  6. Latest version of Xalan (2.2.D10) is significantly better than an eralier version (2.1.0). This is evident from the table below:

    Input SizeProcessing TimeMemory Used
    xalan-2.1.0xalan-2.2.D10xalan2.1.0xalan-2.2.D10
    MEDIUM8.57s2.48s4.7MB2.53MB
    BIG756.0s38.0s46.6MB22.7MB

    The good news is that xalan performance is improving. However, as of now, you are better of avoiding XSL transformations in time critical situations.

------------------