wood burning stoves 2.0*
The moose likes Performance and the fly likes Performance between ..searching in . hashmap or xml document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Performance between ..searching in . hashmap or xml document" Watch "Performance between ..searching in . hashmap or xml document" New topic
Author

Performance between ..searching in . hashmap or xml document

rachana ravali
Ranch Hand

Joined: Jun 20, 2006
Posts: 32
Hi,
I wrote some java jdbc code to fetch the data from the database and store it in an xml document .This xml document is updated for every 24 hours.

When ever a search query comes i need to search in the xml file for the given data.

I want to know whether this is an efficient/good way to do searching , to avoid database call every time a search request comes.

Or storing the data in hashmap (key=column1,value=column2) and searching in them improves performance.

I will at most 25000 rows in the database.

Thanks in advance
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Its impossible to say from what you have described. Premature Optimization is a sin.

If you consider the data from the database as an opaque object, it would seem that a simple caching scheme would address any performance issues if you have them. But first, do you really have a performance problem on the Java side? Have you properly setup the indexes for your RDMBS?

damodar kumar
Ranch Hand

Joined: May 19, 2008
Posts: 77

There will not be any performance issue by fetching from database instead of storing it in HashMap or Xml file and again fetching it .

fetching from xml will take more time than from database, as you have to parse the entire xml file, if the data is more which takes much time as i experienced the issue.


<a href="http://stackoverflow.com/users/668970/user668970" rel="nofollow">
<img src="http://stackoverflow.com/users/flair/668970.png" >
</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Am I correct in assuming that the entire XML document parsed into a DOM is not a burden on memory?

If so you can use a one-time parsing step to create a HashMap in which the values are references to the XML Elements you need to retrieve. This is fast and still preserves the XML structure of the associated data.

Bill
rachana ravali
Ranch Hand

Joined: Jun 20, 2006
Posts: 32
Thanks Pat Farrell,Damodhar Kumar and William Brogden for giving replies.

William,
I am using a SAX parser to parse the document and while parsing i have kept the elements in a hashmap.
I thought DOM will eat soo much of memory space.... am i wrong ?
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

DOM parsers uses up too much memory as it stores the entire XML document in memory as a Document object. If you end up doing the same by maintaining the XML but as a Map instance, I dont see any significant advantage except for the fact hat retrieval of associated values could be faster in the case of a Map as it would not require you to iterate through the entire DOM tree. It again would depend on the structure of the XML and the how the map is organized?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I am using a SAX parser to parse the document and while parsing i have kept the elements in a hashmap.


DOM does use alot of memory but the decision depends on how big the document is, the exact access you need, etc etc. If you have it working - don't change anything just to be chasing a possibly illusionary performance gain.

With SAX, watch out for the characters() method - you don't always get the full text in a single call.

Bill
 
wood burning stoves
 
subject: Performance between ..searching in . hashmap or xml document
 
Similar Threads
Binary XML-- Any Decoder for it --
Search large xml files
XML vs Database
XML Reading vs. MySQL Querying. which one should I choose?
XML Databases instead of good old RDBMS?