You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by swirl <sw...@yahoo.com> on 2013/07/17 05:11:13 UTC

Running Uima in Tomcat (memory issue)

I am wrapping a Uima analysis engine in a Tomcat JSF webapp.

This AE loads and parses a large model file (300Mb).

I can call the AE and run it using SimplePipeline.runPipeline() via the 
webapp UI.

However, the large model took up a large memory chunk that won't go away even 
after the AE is run to completion. 

Does Uima do any clean up of in-memory object instances after the AE is 
completed?

 




Re: Running Uima in Tomcat (memory issue)

Posted by Marshall Schor <ms...@schor.com>.
On 7/16/2013 11:11 PM, swirl wrote:
> I am wrapping a Uima analysis engine in a Tomcat JSF webapp.
>
> This AE loads and parses a large model file (300Mb).
>
> I can call the AE and run it using SimplePipeline.runPipeline() via the 
> webapp UI.
>
> However, the large model took up a large memory chunk that won't go away even 
> after the AE is run to completion. 
>
> Does Uima do any clean up of in-memory object instances after the AE is 
> completed?
The application that embeds UIMA (SimplePipeline) includes a call (at the end of
processing) to the destroy() method.  This propagated to all annotator
implementations in the pipeline, and they can use this to unload things they
might have loaded.

-Marshall

Re: Running Uima in Tomcat (memory issue)

Posted by Richard Eckart de Castilho <ri...@gmail.com>.
Am 17.07.2013 um 10:19 schrieb swirl <sw...@yahoo.com>:

> Richard Eckart de Castilho <ri...@...> writes:
> 
>> 
>> Am 17.07.2013 um 05:11 schrieb swirl <sw...@...>:
>> 
>>> I am wrapping a Uima analysis engine in a Tomcat JSF webapp.
>>> 
>>> This AE loads and parses a large model file (300Mb).
>>> 
>>> I can call the AE and run it using SimplePipeline.runPipeline() via the 
>>> webapp UI.
>>> 
>>> However, the large model took up a large memory chunk that won't go away even 
>>> after the AE is run to completion. 
>>> 
>>> Does Uima do any clean up of in-memory object instances after the AE is 
>>> completed?
> 
>> In a webapp context, to avoid long initialization times, I would
>> recommend creating an instance of the AnalysisEngine and keep it
>> around. Use some queuing to make sure it never used by more than
>> one request at a time. UIMA AEs are not really thread safe.  
>> No worries about garbage collection here, because the AE will
>> live as long as your application is running.
>> 
> 
> Thanks Richard for your quick and informative response.
> 
> You mentioned keeping around a instance of the AE, sorry for the noob 
> question but what is the method you propose? 
> 
> This? http://stackoverflow.com/questions/5668820/sharing-a-class-instance-
> between-all-users-with-tomcat 

There are many ways to do that I suppose. Since I usually build my applications
with Spring, I'd just turn the AE into a Spring bean. You can store it in the
Tomcat application context. You could also just apply the singleton pattern.

Whatever works best for you.

Cheers,

-- Richard


Re: Running Uima in Tomcat (memory issue)

Posted by swirl <sw...@yahoo.com>.
Richard Eckart de Castilho <ri...@...> writes:

> 
> Am 17.07.2013 um 05:11 schrieb swirl <sw...@...>:
> 
> > I am wrapping a Uima analysis engine in a Tomcat JSF webapp.
> > 
> > This AE loads and parses a large model file (300Mb).
> > 
> > I can call the AE and run it using SimplePipeline.runPipeline() via the 
> > webapp UI.
> > 
> > However, the large model took up a large memory chunk that won't go away 
even 
> > after the AE is run to completion. 
> > 
> > Does Uima do any clean up of in-memory object instances after the AE is 
> > completed?
> 
 
> In a webapp context, to avoid long initialization times, I would
> recommend creating an instance of the AnalysisEngine and keep it
> around. Use some queuing to make sure it never used by more than
> one request at a time. UIMA AEs are not really thread safe.  
> No worries about garbage collection here, because the AE will
> live as long as your application is running.
>  

Thanks Richard for your quick and informative response.

You mentioned keeping around a instance of the AE, sorry for the noob 
question but what is the method you propose? 

This? http://stackoverflow.com/questions/5668820/sharing-a-class-instance-
between-all-users-with-tomcat 


Re: Running Uima in Tomcat (memory issue)

Posted by Richard Eckart de Castilho <ri...@gmail.com>.
Am 17.07.2013 um 05:11 schrieb swirl <sw...@yahoo.com>:

> I am wrapping a Uima analysis engine in a Tomcat JSF webapp.
> 
> This AE loads and parses a large model file (300Mb).
> 
> I can call the AE and run it using SimplePipeline.runPipeline() via the 
> webapp UI.
> 
> However, the large model took up a large memory chunk that won't go away even 
> after the AE is run to completion. 
> 
> Does Uima do any clean up of in-memory object instances after the AE is 
> completed?

UIMA doesn't clean up anything. It leaves this job to the garbage collection
facility of the JVM. That said, I know of nothing that UIMA would do to
prevent garbage collection.

If your model is actually a serialized Java object, check that it doesn't 
write to static variables and in that way prevents itself from being 
garbage collected.

In a webapp context, to avoid long initialization times, I would
recommend creating an instance of the AnalysisEngine and keep it
around. Use some queuing to make sure it never used by more than
one request at a time. UIMA AEs are not really thread safe.  
No worries about garbage collection here, because the AE will
live as long as your application is running.

Alternatively maintain a pool of AnalysisEngines that may grow if
the number of concurrent users grow. When the number of concurrent
users get less, the pool should automatically shut down unused
AnalysisEngines after some idle time. In that case, you'd want
to worry about garbage collection again.

It may be possible to encapsulate the large model in an external
resource and share it amongst your AnalysisEngine instances via a
shared ResourceManager. If you use third-party UIMA components,
it is quite likely that you have to extend them to use external
resources. The only components I know that currently wrap models in
external resources are the OpenNLP UIMA components. Even there,
I'm not sure though if actual model wrapping implementation
allows to safe memory.

However, mind that the model itself may not be thread safe.

Cheers,

-- Richard