Hi guys,
We're doing some XML-RPC pushing between the server and our clients and we recently found that our way of building the XML message is a bottleneck in our process.
We do it the basic way: stringBuffer.append("<xml>").append("<client>").append("<name>").append(userEntityBean.getUsername())...
The thing is really going slow and we're already catching all the non-user related data.
I was suggested to use a DOM, replace the user specific data and output the message but AFAIK any toXML() method is also based on stringBuffer(). Is there any faster option?
We're using Weblogic 7.00.1 if it's reelevant.
Thanks!
Gerard.
-
Fastest way to build up a XML message. (9 messages)
- Posted by: Gerard Maas
- Posted on: October 27 2002 09:02 EST
Threaded Messages (9)
- Fastest way to build up a XML message. by Dave Wolf on October 27 2002 16:11 EST
- Fastest way to build up a XML message. by gareth stenson on October 27 2002 20:04 EST
- Fastest way to build up a XML message. by somal sood on October 28 2002 02:27 EST
- Template Class. by Gerard Maas on October 28 2002 06:12 EST
-
Template Class. by Lasse Koskela on October 28 2002 08:53 EST
- Small update. by Gerard Maas on October 30 2002 06:08 EST
- Template Class. by somal sood on October 29 2002 01:08 EST
-
Template Class. by Lasse Koskela on October 28 2002 08:53 EST
- Template Class. by Gerard Maas on October 28 2002 06:12 EST
- Fastest way to build up a XML message. by stephen smithstone on October 28 2002 05:41 EST
- Fastest way to build up a XML message. by anecss anecss on December 29 2002 02:40 EST
-
Fastest way to build up a XML message.[ Go to top ]
- Posted by: Dave Wolf
- Posted on: October 27 2002 16:11 EST
- in response to Gerard Maas
Gerard,
How much of your document is the same every time? If alot of it is identical every time, you might find it faster to build a template with tokens for the data to be changed, and then only replace the tokens.
Dave Wolf
Personified Technologies LLC -
Fastest way to build up a XML message.[ Go to top ]
- Posted by: gareth stenson
- Posted on: October 27 2002 20:04 EST
- in response to Gerard Maas
Part of the problem may be the remote calls to the ejbs, i.e. entitybean.getName(). I think that you need to get the data in the object you are using to build the xml. -
Fastest way to build up a XML message.[ Go to top ]
- Posted by: somal sood
- Posted on: October 28 2002 02:27 EST
- in response to Gerard Maas
Hi
My current project is purely XML Messaging based and we have used a template class to generate the XML. The class returns whole XML String by using obj.getExternalMessage()
The template class use series of getter/setter methods which is used to set member variables from the calling class. Hence generation of XML is concentrated at one place and biggest advantage is that incase your schema changes, you need to modify at one place. Hence clean code and high maintainability.
We are using websphere and the response time (the time when request is sent to server and response generated by server) is too good < 3 sec per request. Believe me our XML is very complex and handles 30 entities, and performance is good.
Hope this will solve your problem.
Somal -
Template Class.[ Go to top ]
- Posted by: Gerard Maas
- Posted on: October 28 2002 06:12 EST
- in response to somal sood
Hi,
Thanks for the tip. The template class you're referring to is a simple class with set's and a function to produce the xml? A kind of class with a toString() in XML ?
I agree with Gareth in that time is spent going to the entities but that is obviously unavoidable.
The token idea sounds good but again, how to I assamble the message? I'll end up with StringBuffer() as I do now and at the end I'll have no win.
The template suggestion will help me keep things maintainable as the stringbuffer.append().append().append().append() is becoming a hell.
Somal, I'd like to know the details of your template method, if possible.
Thanks to all!
Gerard. -
Template Class.[ Go to top ]
- Posted by: Lasse Koskela
- Posted on: October 28 2002 08:53 EST
- in response to Gerard Maas
Of course you need to get the information from the entity beans, but you should do them with a single remote call returning a Value Object / Data Transfer Object containing all the finer grained values. That improves performance as the network call and marshalling is made only once.
Also, you can improve the performance of using StringBuffer if you combine your append().append().append()... into as few final static String's as possible. Also, remember to set the initial size of the StringBuffer into something convenient when instantiating it: new StringBuffer(1024);
I mean, instead of
buffer.append("<root>").append("<sub>");
buffer.append("<value>").append(someValue).append("</value>");
buffer.append("</sub>").append("</root>");
Do something like this
buffer.append("<root><sub><value>");
buffer.append(someValue);
buffer.append("</value></sub></root>");
and replace "abc" with final static String ABC -
Small update.[ Go to top ]
- Posted by: Gerard Maas
- Posted on: October 30 2002 06:08 EST
- in response to Lasse Koskela
Lasse,
I did some tests regarding the use of inline declared strings ("ABC") vs. static final String ABC = "ABC"
when appended to a string or stringbuffer.
In both cases using the inline String was added 5x faster than the static final version.
Just for your info.
-regards,
Gerard. -
Template Class.[ Go to top ]
- Posted by: somal sood
- Posted on: October 29 2002 01:08 EST
- in response to Gerard Maas
Hi Gerard
We also tried to use same methology which you were using. But it doesn't work well on performance issue as one of the client requirement was Max. 3 sec response time (infact we never bother about multiple 'append' expressions).
We use castor to generate the classes. It has very efficient way to marshal and unmarshal the XML. To made it more efficient we write some wrappers to it and it all works.
I would suggest you to use castor in your case and you will be save by multiple 'append()' expressions.
Regarding wrappers, these are the templates which are the navigations, locators and counters and perform the respective functions for different entities.(Example: A person can have multiple address. Hence navigator will traverse all address one by one. Locators are used to locate particular address. Counters give you total number of address person has.)
Hope you must have got an idea how to implement it.
Somal -
Fastest way to build up a XML message.[ Go to top ]
- Posted by: stephen smithstone
- Posted on: October 28 2002 05:41 EST
- in response to Gerard Maas
may be have a look @ JDom www.jdom.org its been designed to simplfy the build of xml docs -
Fastest way to build up a XML message.[ Go to top ]
- Posted by: anecss anecss
- Posted on: December 29 2002 02:40 EST
- in response to Gerard Maas
take a look at cocoon generators