You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Terence Lai <tl...@trekspace.com> on 2004/08/18 00:39:51 UTC

RE: OutOfMemoryError

Sorry. I should make it more clear in my last email. I have implemented an EJB Session Bean executing the Lucene search. At the beginning, the session been is working fine. It returns the correct search results to me. As more and more search requests being processed, the server ends up having the OutOfMemoryError. If I restart the server, every thing works fine again.

Terence

> Hi All,
> 
> I am getting a OutOfMemoryError when I deploy my EJB application. To debug the problem, 
> I wrote the following test program:
> 
>     public static void main(String[] args) {
>         try {
>             Query query = getQuery();
> 
>             for (int i=0; i<1000; i++) {
>                 search(query);
>                 
>                 if ( i%50 == 0 ) {
>                     System.out.println("Sleep...");
>                     Thread.currentThread().sleep(5000);
>                     System.out.println("Wake up!");
>                 }
>             }            
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> 
>     private static void search(Query query) throws IOException {
>         FSDirectory fsDir = null;
>         IndexSearcher is = null;
>         Hits hits = null;
>         
>         try {
>             fsDir = FSDirectory.getDirectory("C:\\index, false);
>             is = new IndexSearcher(fsDir);
>             SortField sortField = new SortField("profile_modify_date",
>                 SortField.STRING, true);
> 
>             hits = is.search(query, new Sort(sortField));
>         } finally {
>             if (is != null) {
>                 try {
>                     is.close();
>                 } catch (Exception ex) {
>                 }
>             }
>             
>             if (fsDir != null) {
>                 try {
>                     is.close();
>                 } catch (Exception ex) {
>                 }
>             }
>         }
>         
>     }
> 
> In the test program, I wrote a loop to keep calling the search method. Everytime 
> it enters the search method, I would instantiate the IndexSearcher. Before I exit 
> the method, I close the IndexSearcher and FSDirectory. I also made the Thread sleep 
> for 5 seconds in every 50 searches. Hopefully, this will give some time for the 
> java to do the Garbage Collection. Unfortunately, when I observe the memory usage 
> of my process, it keeps increasing until I got the java.lang.OutOfMemoryError.
> 
> Note that I invoke the IndexSearcher.search(Query query, Sort sort) to process the 
> search. If I don't specify the Sort field(i.e. using IndexSearcher.search(query)), 
> I don't have this problem, and the memory usage keeps at a very static level.
> 
> Does anyone experience a similar problem? Did I do something wrong in the test program. 
> I throught by closing the IndexSearcher and the FSDirectory, the memory will be 
> able to release during the Garbage Collection.
> 
> Thanks,
> Terence
> 
> 
> 
> 
> ----------------------------------------------------------
> Get your free email account from http://www.trekspace.com
>           Your Internet Virtual Desktop!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 




----------------------------------------------------------
Get your free email account from http://www.trekspace.com
          Your Internet Virtual Desktop!

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


RE: OutOfMemoryError

Posted by John Moylan <jo...@rte.ie>.
Terence, 

This may help:
http://issues.apache.org/bugzilla/show_bug.cgi?id=30628
I had the problem, above...but I managed to resolve it be not closing
the indexsearcher. Instead I now reuse the same indexsearcher all of the
time within my JSP code as an application variable. GC keeps memory in
check on my System now and search is faster too.

Also, make sure that you are using 1.4.1 as it fixes a sort caching
problem in 1.4

  if ((application.getAttribute("searcher")) != null){
    searcher = (IndexSearcher)application.getAttribute("searcher");
  }	
  else {
    searcher = new IndexSearcher(IndexReader.open(indexName));
      application.setAttribute("searcher", searcher);
  }
      	
  	   


On Tue, 2004-08-17 at 23:39, Terence Lai wrote:
> Sorry. I should make it more clear in my last email. I have implemented an EJB Session Bean executing the Lucene search. At the beginning, the session been is working fine. It returns the correct search results to me. As more and more search requests being processed, the server ends up having the OutOfMemoryError. If I restart the server, every thing works fine again.
> 
> Terence
> 
> > Hi All,
> > 
> > I am getting a OutOfMemoryError when I deploy my EJB application. To debug the problem, 
> > I wrote the following test program:
> > 
> >     public static void main(String[] args) {
> >         try {
> >             Query query = getQuery();
> > 
> >             for (int i=0; i<1000; i++) {
> >                 search(query);
> >                 
> >                 if ( i%50 == 0 ) {
> >                     System.out.println("Sleep...");
> >                     Thread.currentThread().sleep(5000);
> >                     System.out.println("Wake up!");
> >                 }
> >             }            
> >         } catch (Exception e) {
> >             e.printStackTrace();
> >         }
> >     }
> > 
> >     private static void search(Query query) throws IOException {
> >         FSDirectory fsDir = null;
> >         IndexSearcher is = null;
> >         Hits hits = null;
> >         
> >         try {
> >             fsDir = FSDirectory.getDirectory("C:\\index, false);
> >             is = new IndexSearcher(fsDir);
> >             SortField sortField = new SortField("profile_modify_date",
> >                 SortField.STRING, true);
> > 
> >             hits = is.search(query, new Sort(sortField));
> >         } finally {
> >             if (is != null) {
> >                 try {
> >                     is.close();
> >                 } catch (Exception ex) {
> >                 }
> >             }
> >             
> >             if (fsDir != null) {
> >                 try {
> >                     is.close();
> >                 } catch (Exception ex) {
> >                 }
> >             }
> >         }
> >         
> >     }
> > 
> > In the test program, I wrote a loop to keep calling the search method. Everytime 
> > it enters the search method, I would instantiate the IndexSearcher. Before I exit 
> > the method, I close the IndexSearcher and FSDirectory. I also made the Thread sleep 
> > for 5 seconds in every 50 searches. Hopefully, this will give some time for the 
> > java to do the Garbage Collection. Unfortunately, when I observe the memory usage 
> > of my process, it keeps increasing until I got the java.lang.OutOfMemoryError.
> > 
> > Note that I invoke the IndexSearcher.search(Query query, Sort sort) to process the 
> > search. If I don't specify the Sort field(i.e. using IndexSearcher.search(query)), 
> > I don't have this problem, and the memory usage keeps at a very static level.
> > 
> > Does anyone experience a similar problem? Did I do something wrong in the test program. 
> > I throught by closing the IndexSearcher and the FSDirectory, the memory will be 
> > able to release during the Garbage Collection.
> > 
> > Thanks,
> > Terence
> > 
> > 
> > 
> > 
> > ----------------------------------------------------------
> > Get your free email account from http://www.trekspace.com
> >           Your Internet Virtual Desktop!
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> > 
> 
> 
> 
> 
> ----------------------------------------------------------
> Get your free email account from http://www.trekspace.com
>           Your Internet Virtual Desktop!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
-- 
John Moylan
RTÉ ePublishing,
Montrose House,
Donnybrook,
Dublin 4
T: +353 1 2083564
E: john.moylan@rte.ie


******************************************************************************
The information in this e-mail is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this e-mail by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
Please note that emails to, from and within RT� may be subject to the Freedom
of Information Act 1997 and may be liable to disclosure.
******************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org