• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutOfMemoryError on a serlvet

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is not exactly a Weblogic problem, but WL is what we use. This servlet (a report) can generate a huge page (>1M) depending on data amount. And it can thus use a lot of memory. Occasionally, when many many requests come in at the same time we can get the OutOfMemoryError. We added some memory cleaning procedures and also implemented the SingleThreadModel. These helped and the chances of getting the error are way down.
But the question is, what else can we do to "eliminate" the OutOfMemoryError ?
TIA
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always add more memory to the JVM heap for WebLogic (assuming you have enough physical memory on the box). Without knowing more about your situation (ie. why 1MB pages are being generated) I can't really offer much help.
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Chris:
We'd like to rethink about it too, i.e. the report is really big and we should not transport such big content over to the browser. Nevertheless, the important info. for you is that even when the HTML is about 1MB, the heap memory used by JVM is about 5 MB when we do the manipulation. We have already done some cleaning such as use StringBuffer instead of String and create as less objects as possible. The memory allocation currently is 96MB. So yes we can increase that, but even if we have 128MB say. When 20 people are hitting the servlets at exactly the same time, they'd use up to 100MB of memory. That's why we use SingleThreadModel for this servlet.
I guess my question is a more general one. Our hits are not so many. But I wonder for those major website, say getting hits 50 or more every second, how they handle this kind of issue?
Regards,
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several things you can do, but in this case the most important thing is to reduce the amount of memory you are using.
One way is to cache the results so you do not have to spend the memory to recalculate. This only works if you will give the same large document back to several users. If each user gets their own custom document, then this will not work.
Or, if the documents change less frequently, you could set up another process to periodically recompute them and write them as html (or whatever format) plain files. Then the web server does not use a servlet, but just returns the correct file.
Another thing you can do is limit the number of concurrent threads that can process the request. This is essentially what you have done with Single Thread model, but the only choice you have there is "one" or "many". If this is the only function your site is performing, and as you say you do not have large number of users, you can reduce the thread pool size. I think the default is something like 15 threads - if you turn this down to 3, then you could never have more than 3 user requests happening at once.
If these things do not work for you, then you need to work hard to reduce the memory requirements of your process AND increase the heap size of your VM and the physical memory on the server. It is not uncommon to have a heap size of 512 Mb for a large server (in this case, I'd want the machine to have at least 1 Gb physical RAM).
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David:
Thanks. I think it is a good summary. Althouth none of them is of too much of surprise to me, I think it is clear that we have to put more effort on reducing memory usuage. Unfortunately, each request is different from different user, so we can't really do the first suggestion here.
Regards,
 
reply
    Bookmark Topic Watch Topic
  • New Topic