Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance between ..searching in . hashmap or xml document

 
rachana ravali
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
Android Chrome MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic