This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes memory problems on the server!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "memory problems on the server!!!" Watch "memory problems on the server!!!" New topic
Author

memory problems on the server!!!

pankaj kak
Greenhorn

Joined: Apr 14, 2001
Posts: 3

i'm facing serious memory problems on the site we had build using
Servlets.
the site gives certain unknown errors due to the heavy traffic.
what can be done to minimise the memory leaks???
is there a way to minimise these loses through your code..
please suggest....
the server is Apache server and its ram is aroung 1GB..
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Pankaj,
Could you elaborate on the kind of web application you are hosting?
There are some performance hits that might occur in your web applications.Some of the troubleshooting could be done by :

  1. Using Connection Pooling
  2. Avoiding use of synchronized blocks, as much as possible.Use local instances instead
  3. If objects are huge in size , consider serializing and storing the object into an external resource like a file or even DB

  4. This seems to be an interesting topic.Please provide us with more inputs.
    Regards,
    Sandeep Desai
    vgdesai@vsnl.com

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

    5. [This message has been edited by Desai Sandeep (edited April 14, 2001).]
pankaj kak
Greenhorn

Joined: Apr 14, 2001
Posts: 3

we had launched a site on the apache web server using the postgres database...
the site was going fine for quite some time but due to the increasing rush on the site..there have been some problems on the site..the site is taking lots of Server RAM.
the pages get blank some times.
probably there are some memory leakages..
as the rush on the server gets less..it works perfectly fine...
are there ways to reduce these memory leakages..or is there any other possible reason for such behaviour of the site..
ofcourse we r using the Connection pooling and it seems to work fine...beacuase i counted them..they r always less than the maximum limit of 32.
do we need to increase the number of connections..?
please suggest..
thank you.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Pankaj,
I feel your project involves lot of Object Creation with considerable size.I assume you are putting that in the session or application implicit object.
Just check your design, if :
1. You could put the objects like Connection, at the application Level.In case it is at session level, it would be created for every instance of the browser.This could hog your memory resources.
2. You could also use a GC mechanism, if required to nullify the unwanted references.
3. Use local instances instead of synchronized blocks to serve the requests faster
Let me know if the above points help you for this performance hit
Regards,


------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
There is a lot that can be done to optimize typical servlet CPU and memory use. There was a Thread about books on the topic just this last week.
I have found it very helpful to have a special servlet for administrator use only that can query current available memory, number of connections in use, etc. - If you are using sessions, you can have a HttpSessionBindingListener to help you keep track of the number of active sessions.
Bill

------------------
author of:
prashant patel
Ranch Hand

Joined: May 02, 2000
Posts: 69
Hi Pankaj,
I would like to know if you have solved the problem. Also you have not mentioned which application server you are using.
We have also tried to implemented connection pooling but,with
websphere 3.5 the performance for very poor. could you pls share your know how with us.


prashz
ivan paniagua
Greenhorn

Joined: Sep 28, 2001
Posts: 1
Hi Pankaj,
If you are using apache with servlet maybe you are using tomcat
(this assumption because you are using apache and postgresql, open products) and if this is the case with version 3.2 of tomcat you can use thread pool similar to connection pool but reusing threads.
The default configuration is in average for 10-40 concurrent request and you should modify this configuration in the archive server.xml in the section of <Connector>.
Well, this is an specific and restrictive response only for tomcat but if you are using other servlet container or if you are using other application server more sophisticated,
maybe have similar mechanism (for exmaple Weblogic attempts to use HTTP persistent connection).
I really want know if you using tomcat or not and if this advice help you.
If you have any question or suggestion just write me and sorry for my english.
Ivan Paniagua.
id_ramallo@hotmail.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: memory problems on the server!!!