0

I planning on reading profile data from a xml file in JSP.

Now i can either read it and store the important information in single session variables or just put the whole section from the xml file in a jdom document and put that into a single session variable.

In your experience, will the data size impact the big or negligible ?

John Frost
  • 673
  • 1
  • 10
  • 24

3 Answers3

3

JDOM 2.0.0 - released yesterday (I am the maintainer) has an improved memory footprint... it uses less than 10x as much memory as the input document. Additionally, if you use the 'SlimJDOMFactory' when parsing the XML, you use even less. A typical 275KB document is parsed in 1.5Meg using the SlimJDOMFactory. See the performance metrics for JDOM 2.0.0 at http://hunterhacker.github.com/jdom/jdom2/performance.html and search for SlimJDOMFactory to get the results using the (slower) but more efficient factory.

This in no way answers your question, because in reality, it all depends on your input data size. My experience, and I am biased, is that for small documents it's easier to just load it all in memory, and only 'sweat it' for the big ones.

reevesy
  • 3,452
  • 1
  • 26
  • 23
rolfl
  • 17,539
  • 7
  • 42
  • 76
1

There is a rule of thumb when it comes down to storing XML in memory with DOM. The size of the XML-file * 10. So if you XML-File is 1MB big then you will need 10MB memory to store it.

But in my experience i would never ever store a DOM document in memory. Once some student tried to do that, but the XML-File was 50MB big, so guess what happens? We ran out of Memory.

For your case i would create a class which can hold all the relevant information, fill the class by reading the xml.

Do you really need to store the profile data in the session? Do you really need it all the time? Sometime it is enough to just the an id or a small class.

Adi
  • 140
  • 5
  • Well ok, thanks for the rule of thumb. I don't need to do it, i would just be easier. My xml files are a maximum of 1Kb. Are there differences between the different parsers? – John Frost Apr 09 '12 at 15:05
  • Is there also a rule of thumb for the session data? – John Frost Apr 09 '12 at 15:07
  • I want to avoid reading the same data from my xml file all the time. – John Frost Apr 09 '12 at 15:08
  • The less you store in the session the better it is. You have to take into account that if you store 1MB per user in the session this will be multiplied by the user using your system. So if there are 100 users, your application will consume 100MB. This can easily reach a critical limit. – Adi Apr 09 '12 at 15:30
0

Well, the more objects you store in memory the less free heap memory you'll have, there isn't a way around that.

It depends on your application domain really.

But in general people use cache solutions (ehCache is one, from the top of my head) between the datasource (your xml file/s) and their application domain model.

The cache expires or is cleared on demand, therefore you have reasonable control of your objects, and the heap memory they occupy.

Svilen
  • 1,377
  • 1
  • 16
  • 23
  • Well basically I mean the difference between storing data in a jdom object and storing data in a var object. – John Frost Apr 09 '12 at 15:01
  • Yep, it depends on what you need. If you can get away with storing just parts of the XML in memory then you should definitely go with that. In my experience the XML markup is almost never needed at runtime, just used for persisting data. – Svilen Apr 09 '12 at 16:11