dcsimg
Serialization with respect to performance.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, July 30, 2002 04:18 AM

We have a requirement wherein I have to convert objects in to plain text messages, which will be put in a JMS queue. The message will be read from JMS queue some time later and the object will be reconstructed. To accomplish this, this is the current method we are using. 1) The object will have a method toXml() , which will convert the object values in to a XML. 2) Put this XML as text message in the queue 3) Retrieve the XML from Queue. 4) Parse the XML and reconstruct the object (A framework is already available for this conversion; this involves a conversion of XML into a hashtable, with a database lookup providing keys for hashtable. The o   More>>
			
We have a requirement wherein I have to convert objects in
to plain text messages, which will be put in a JMS queue.
The message will be read from JMS queue some time later and
the object will be reconstructed.



To accomplish this, this is the current method we are using.
			
1) The object will have a method toXml() , which will convert the object values in to a XML.
2) Put this XML as text message in the queue
3) Retrieve the XML from Queue.
4) Parse the XML and reconstruct the object
(A framework is already available for this conversion; this
involves a conversion of XML into a hashtable, with a
database lookup providing keys for hashtable. The object
will be constructed by reading values from Hashtable)






			
Now, a new implementation has been proposed to accomplish
the same.



			
1) Serialize the object into a string buffer.
2) Put this string in the queue as the text message.
3) Retrieve this text message from the queue.
4) De-serialize the string to create the object.






			
The idea behind the proposed changes is to avoid writing
lot of code to convert the object to XML and re-construct
the object from XML. In the new method, serialization is
taken care of by Java and we write very little code.
But, my only concern here is about performance. Do you
think the performance will be degraded by the new changes?
In other words, how costly an affair is this
serialization/de-serialization process as compared to
creating/parsing XML?



Is it advisable to go for the new implementation?    <<Less

Re: Serialization with respect to performance.

Posted By:   Eric_Lindauer  
Posted On:   Sunday, August 18, 2002 07:15 PM

Hi,



Short answer: yes. Your XML plan will get the job done, but what you are really talking about is implementing Serialization yourself, because you are afraid Serialization won't be fast enough. To make this decision from the beginning without trying Serialization first would be a clear mistake ( amounting to optimizing your code before it's written, always a no-no ).




Given that you've got this mechanism in place already though, there are still some good reasons to change. First, the Serialization mechanism is maintained for you, whereas this XML plan is your own monster. Serialization actually has some tricky parts to it ( like dealing with object reference circularity ), which you may be able to solve too, but why would you want to? Are you really sure your solution is error-free? Java has thousands of people using it, so you can be sure that subtle bugs in Serialization will be found and fixed much more rapidly than bugs in your own XML code.




Besides the advantage of maintenance, I agree with the previous poster that Serialization is likely to offer a performance increase over XML-parsing. Although Serialization is not the speediest thing around, parsing XML is even slower. I've made this switch myself ( more than once now in fact ), and in each case Serialization was a speed improvement.




Hope this helps.

-Eric

Re: Serialization with respect to performance.

Posted By:   Eugene_Kuleshov  
Posted On:   Tuesday, July 30, 2002 06:01 AM

It is not quite clear how you going to serialize to the string buffer. srialization is a binary format and there is stpecial type of JMS messages that can handle it - ObjectMessage (it is a big chance that it might be even not serialized if it will be not sent outside of local queue and not persistant, but it may depend on concrete JMS implementation).



I also believe that performance of the de/serialization is much better then for XML-based approach.
About | Sitemap | Contact