• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Performance between ..searching in . hashmap or xml document

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 77
Android MyEclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic