You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Vikrant sutar <vi...@yahoo.com> on 2004/09/14 02:00:22 UTC

Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Hi All,

I have a query related to application implementation.
We have an application where we load 3 schemas into
memory. Now we want to validate 3 different kinds of
xmls at run time with appropriate XML Schema. 
In short our application is multithreaded application.

Currently for each request we create NEW instances of
DocumentBuilderFactory and DocumentBuilder:

DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
factory.newDocumentBuilder();

Document document = builder.parse(xml String);

With All Schema's cached as a File objects in
Singleton class.

My question to all of you is:

Is it absolutely required to create an instances of
"DocumentBuilderFactory and DocumentBuilder" for each
request? [as it is performance hit]

Is there any way we can create application-wide, 3
instances of DocumentBuilder ,initially and re-use
them for all further validation requests for "xml
String" ?

I guess even synchronization can be performance hit.

Please advise me.

Thanks a lot for your help /Vikrant


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@sun.com>.

Paul R Brown wrote:

>
> Hi, Vikrant --
>
> From the description of your application, it sounds like you would 
> benefit from a custom configuration.  As for your other question:
>
>> Is it absolutely required to create an instances of
>> "DocumentBuilderFactory and DocumentBuilder" for each
>> request? [as it is performance hit]
>
>
> It is absolutely NOT necessary.  The last time I profiled things out, 
> the ratio between cost is something like 300:100:1 for 
> DocumentBuilderFactory:DocumentBuilder:Document, i.e., creating a 
> DocumentBuilderFactory is 300 times as expensive (in time) as creating 
> a Document.

Size of XML must have been very small then.

Neeraj

>
> Your best bet is to set up some rudimentary pooling (e.g., using 
> Commons Pool) and work from there.
>
> Others can probably comment on how to configure individiual Xerces 
> instances for best performance based on your scenario.
>
>     -- Paul
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@sun.com>.

Paul R Brown wrote:

>
> Hi, Vikrant --
>
> From the description of your application, it sounds like you would 
> benefit from a custom configuration.  As for your other question:
>
>> Is it absolutely required to create an instances of
>> "DocumentBuilderFactory and DocumentBuilder" for each
>> request? [as it is performance hit]
>
>
> It is absolutely NOT necessary.  The last time I profiled things out, 
> the ratio between cost is something like 300:100:1 for 
> DocumentBuilderFactory:DocumentBuilder:Document, i.e., creating a 
> DocumentBuilderFactory is 300 times as expensive (in time) as creating 
> a Document.

Size of XML must have been very small then.

Neeraj

>
> Your best bet is to set up some rudimentary pooling (e.g., using 
> Commons Pool) and work from there.
>
> Others can probably comment on how to configure individiual Xerces 
> instances for best performance based on your scenario.
>
>     -- Paul
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Paul R Brown <pr...@fivesight.com>.
Hi, Vikrant --

 From the description of your application, it sounds like you would 
benefit from a custom configuration.  As for your other question:

> Is it absolutely required to create an instances of
> "DocumentBuilderFactory and DocumentBuilder" for each
> request? [as it is performance hit]

It is absolutely NOT necessary.  The last time I profiled things out, 
the ratio between cost is something like 300:100:1 for 
DocumentBuilderFactory:DocumentBuilder:Document, i.e., creating a 
DocumentBuilderFactory is 300 times as expensive (in time) as creating 
a Document.

Your best bet is to set up some rudimentary pooling (e.g., using 
Commons Pool) and work from there.

Others can probably comment on how to configure individiual Xerces 
instances for best performance based on your scenario.

	-- Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@Sun.COM>.

Vikrant sutar wrote:

>My question to all of you is:
>
>Is it absolutely required to create an instances of
>"DocumentBuilderFactory and DocumentBuilder" for each
>request? [as it is performance hit]
>
>Is there any way we can create application-wide, 3
>instances of DocumentBuilder ,initially and re-use
>them for all further validation requests for "xml
>String" ?
>

JAXP 1.3 solves this problem by providing a way to reset [1] the 
instance created.
These APIs are also part of JAVA platform J2SE 5.0

Neeraj

[1] 
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder.html#reset()

>I guess even synchronization can be performance hit.
>
>Please advise me.
>
>Thanks a lot for your help /Vikrant
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Paul R Brown <pr...@fivesight.com>.
Hi, Vikrant --

 From the description of your application, it sounds like you would 
benefit from a custom configuration.  As for your other question:

> Is it absolutely required to create an instances of
> "DocumentBuilderFactory and DocumentBuilder" for each
> request? [as it is performance hit]

It is absolutely NOT necessary.  The last time I profiled things out, 
the ratio between cost is something like 300:100:1 for 
DocumentBuilderFactory:DocumentBuilder:Document, i.e., creating a 
DocumentBuilderFactory is 300 times as expensive (in time) as creating 
a Document.

Your best bet is to set up some rudimentary pooling (e.g., using 
Commons Pool) and work from there.

Others can probably comment on how to configure individiual Xerces 
instances for best performance based on your scenario.

	-- Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@Sun.COM>.

Vikrant sutar wrote:

>My question to all of you is:
>
>Is it absolutely required to create an instances of
>"DocumentBuilderFactory and DocumentBuilder" for each
>request? [as it is performance hit]
>
>Is there any way we can create application-wide, 3
>instances of DocumentBuilder ,initially and re-use
>them for all further validation requests for "xml
>String" ?
>

JAXP 1.3 solves this problem by providing a way to reset [1] the 
instance created.
These APIs are also part of JAVA platform J2SE 5.0

Neeraj

[1] 
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder.html#reset()

>I guess even synchronization can be performance hit.
>
>Please advise me.
>
>Thanks a lot for your help /Vikrant
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@Sun.COM>.

Rick Bullotta wrote:

>One immediate performance boost was to
>set the appropriate system properties so that the factories use Xerces
>
Right.  Checking for System property is the first step in the factory 
implementation class
lookup mechanism.

Neeraj

>explicitly rather than searching for resources in jar files and .properties
>files on disk each time a builder is created.
>
>Rick Bullotta
>CTO
>Lighthammer Software (http://www.lighthammer.com)
>
>-----Original Message-----
>From: Vikrant sutar [mailto:vikrantsutarm@yahoo.com] 
>Sent: Monday, September 13, 2004 8:00 PM
>To: xerces-j-user@xml.apache.org; xerces-j-dev@xml.apache.org
>Subject: Correct use of DocumentBuilderFactory & DocumentBuilder :
>Multithreaded application
>
>Hi All,
>
>I have a query related to application implementation.
>We have an application where we load 3 schemas into
>memory. Now we want to validate 3 different kinds of
>xmls at run time with appropriate XML Schema. 
>In short our application is multithreaded application.
>
>Currently for each request we create NEW instances of
>DocumentBuilderFactory and DocumentBuilder:
>
>DocumentBuilderFactory.newInstance();
>DocumentBuilder builder =
>factory.newDocumentBuilder();
>
>Document document = builder.parse(xml String);
>
>With All Schema's cached as a File objects in
>Singleton class.
>
>My question to all of you is:
>
>Is it absolutely required to create an instances of
>"DocumentBuilderFactory and DocumentBuilder" for each
>request? [as it is performance hit]
>
>Is there any way we can create application-wide, 3
>instances of DocumentBuilder ,initially and re-use
>them for all further validation requests for "xml
>String" ?
>
>I guess even synchronization can be performance hit.
>
>Please advise me.
>
>Thanks a lot for your help /Vikrant
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Neeraj Bajaj <Ne...@Sun.COM>.

Rick Bullotta wrote:

>One immediate performance boost was to
>set the appropriate system properties so that the factories use Xerces
>
Right.  Checking for System property is the first step in the factory 
implementation class
lookup mechanism.

Neeraj

>explicitly rather than searching for resources in jar files and .properties
>files on disk each time a builder is created.
>
>Rick Bullotta
>CTO
>Lighthammer Software (http://www.lighthammer.com)
>
>-----Original Message-----
>From: Vikrant sutar [mailto:vikrantsutarm@yahoo.com] 
>Sent: Monday, September 13, 2004 8:00 PM
>To: xerces-j-user@xml.apache.org; xerces-j-dev@xml.apache.org
>Subject: Correct use of DocumentBuilderFactory & DocumentBuilder :
>Multithreaded application
>
>Hi All,
>
>I have a query related to application implementation.
>We have an application where we load 3 schemas into
>memory. Now we want to validate 3 different kinds of
>xmls at run time with appropriate XML Schema. 
>In short our application is multithreaded application.
>
>Currently for each request we create NEW instances of
>DocumentBuilderFactory and DocumentBuilder:
>
>DocumentBuilderFactory.newInstance();
>DocumentBuilder builder =
>factory.newDocumentBuilder();
>
>Document document = builder.parse(xml String);
>
>With All Schema's cached as a File objects in
>Singleton class.
>
>My question to all of you is:
>
>Is it absolutely required to create an instances of
>"DocumentBuilderFactory and DocumentBuilder" for each
>request? [as it is performance hit]
>
>Is there any way we can create application-wide, 3
>instances of DocumentBuilder ,initially and re-use
>them for all further validation requests for "xml
>String" ?
>
>I guess even synchronization can be performance hit.
>
>Please advise me.
>
>Thanks a lot for your help /Vikrant
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


RE: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Rick Bullotta <ri...@lighthammer.com>.
I'll be interested in the responses.  We've found significant issues with
the factory and build creation as a result of custom classloaders in some
servlet engines when using Xalan.  One immediate performance boost was to
set the appropriate system properties so that the factories use Xerces
explicitly rather than searching for resources in jar files and .properties
files on disk each time a builder is created.

Rick Bullotta
CTO
Lighthammer Software (http://www.lighthammer.com)

-----Original Message-----
From: Vikrant sutar [mailto:vikrantsutarm@yahoo.com] 
Sent: Monday, September 13, 2004 8:00 PM
To: xerces-j-user@xml.apache.org; xerces-j-dev@xml.apache.org
Subject: Correct use of DocumentBuilderFactory & DocumentBuilder :
Multithreaded application

Hi All,

I have a query related to application implementation.
We have an application where we load 3 schemas into
memory. Now we want to validate 3 different kinds of
xmls at run time with appropriate XML Schema. 
In short our application is multithreaded application.

Currently for each request we create NEW instances of
DocumentBuilderFactory and DocumentBuilder:

DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
factory.newDocumentBuilder();

Document document = builder.parse(xml String);

With All Schema's cached as a File objects in
Singleton class.

My question to all of you is:

Is it absolutely required to create an instances of
"DocumentBuilderFactory and DocumentBuilder" for each
request? [as it is performance hit]

Is there any way we can create application-wide, 3
instances of DocumentBuilder ,initially and re-use
them for all further validation requests for "xml
String" ?

I guess even synchronization can be performance hit.

Please advise me.

Thanks a lot for your help /Vikrant


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


RE: Correct use of DocumentBuilderFactory & DocumentBuilder : Multithreaded application

Posted by Rick Bullotta <ri...@lighthammer.com>.
I'll be interested in the responses.  We've found significant issues with
the factory and build creation as a result of custom classloaders in some
servlet engines when using Xalan.  One immediate performance boost was to
set the appropriate system properties so that the factories use Xerces
explicitly rather than searching for resources in jar files and .properties
files on disk each time a builder is created.

Rick Bullotta
CTO
Lighthammer Software (http://www.lighthammer.com)

-----Original Message-----
From: Vikrant sutar [mailto:vikrantsutarm@yahoo.com] 
Sent: Monday, September 13, 2004 8:00 PM
To: xerces-j-user@xml.apache.org; xerces-j-dev@xml.apache.org
Subject: Correct use of DocumentBuilderFactory & DocumentBuilder :
Multithreaded application

Hi All,

I have a query related to application implementation.
We have an application where we load 3 schemas into
memory. Now we want to validate 3 different kinds of
xmls at run time with appropriate XML Schema. 
In short our application is multithreaded application.

Currently for each request we create NEW instances of
DocumentBuilderFactory and DocumentBuilder:

DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
factory.newDocumentBuilder();

Document document = builder.parse(xml String);

With All Schema's cached as a File objects in
Singleton class.

My question to all of you is:

Is it absolutely required to create an instances of
"DocumentBuilderFactory and DocumentBuilder" for each
request? [as it is performance hit]

Is there any way we can create application-wide, 3
instances of DocumentBuilder ,initially and re-use
them for all further validation requests for "xml
String" ?

I guess even synchronization can be performance hit.

Please advise me.

Thanks a lot for your help /Vikrant


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org