contention during XMLReaderFactory.createXMLReader

Andrew Welch <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <CAEG2duDC3SN-rjop9xo+V0CY=4QRAngVqmrMcuZ3OBghd-krCA@mail.gmail.com>
Hi,

A colleague was doing some performance testing and discovered some
contention at this line of my code:

XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

...which was surprising : ) He informed me it was doing a blocking
operation every time.

Anyway, he went away and went through the Xerces source and found that
if the "org.apache.xerces.xni.parser.XMLParserConfiguration" system
property is not set it does indeed do a blocking operation (in
parsers.ObjectFactory)

To demonstrate this, run the below code with and without the system
property set:

public static void main(String... args) throws Exception {

    //System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
    //        "org.apache.xerces.parsers.XIncludeParserConfiguration");

    long start = System.nanoTime();

    for (int i = 0; i <= 10000; i++) {
        XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    }

    long end = System.nanoTime();
    double millis = (end - start) * 1e-6;

    System.out.println(millis);

}

On my machine it consistently takes around ~2000ms without the system
property, and ~1300ms with.

This is present in both 2.9 and 2.11 as far as I can see.




-- 
Andrew Welch
http://andrewjwelch.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.