You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by Travis Savo <ts...@IFILM.com> on 2004/07/21 02:15:47 UTC

EventQueues and Threads

We discussed in the past a Thread Throttle to limit the number of Threads
for EventQueues.

Really I think the right solution is a Thread Pool, (and/or a Runnable
Queue). If we convert the EventQueue to a Runnable and pull threads from the
pool as they become available (and/or stick the Runnables in a queue for
processing, either way we achieve the same effect: The threads, of which
there are a limited number, get reused), this eliminates the need for a
throttle, and makes much better reuse of Threads, so 'keeping it alive for a
minute' is no longer necessary: The life of the unused Thread itself can be
handled by the Pool.

Does this sound like the right solution to you? Or at least headed in the
direction of the right solution?

I just wanted to check with you before I start down a path that won't lead
to everyone's consent.

-Travis Savo <ts...@ifilm.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


RE: EventQueues and Threads

Posted by Aaron Smuts <aa...@wisc.edu>.
Your implementation works nicely, but we can change it and make it more
configurable.  It should probably use the PooledExecutor with a
BoundedQueue, set to runincurrentthread or discard oldest when full.
The size of the queue and the number of min threads, the idle life, and
the max should be configurable in the cache.ccf.  The admin package I
mentioned will help here. . . .

Aaron

> -----Original Message-----
> From: Travis Savo [mailto:tsavo@IFILM.com]
> Sent: Tuesday, July 20, 2004 7:16 PM
> To: 'Turbine JCS Developers List'
> Subject: EventQueues and Threads
> 
> We discussed in the past a Thread Throttle to limit the number of
Threads
> for EventQueues.
> 
> Really I think the right solution is a Thread Pool, (and/or a Runnable
> Queue). If we convert the EventQueue to a Runnable and pull threads
from
> the
> pool as they become available (and/or stick the Runnables in a queue
for
> processing, either way we achieve the same effect: The threads, of
which
> there are a limited number, get reused), this eliminates the need for
a
> throttle, and makes much better reuse of Threads, so 'keeping it alive
for
> a
> minute' is no longer necessary: The life of the unused Thread itself
can
> be
> handled by the Pool.
> 
> Does this sound like the right solution to you? Or at least headed in
the
> direction of the right solution?
> 
> I just wanted to check with you before I start down a path that won't
lead
> to everyone's consent.
> 
> -Travis Savo <ts...@ifilm.com>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
turbine-jcs-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


RE: Cache Memory Guard

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
In Avalon/Excalibur we have a janitor that runs as a background
task, and peridically checks the available free memory. If
some configurable limit is reached, it asks the registered
stores to free memory. 
If properly configured, this is a really good way of avoiding
OutOfMemory exceptions. In combination with a LRUMemoryCache,
it ensures that old entries are removed first.

Here is the source:
https://svn.apache.org/repos/asf/excalibur/trunk/components/store/src/java/o
rg/apache/excalibur/store/StoreJanitor.java

(I think it also can activate the garbage collector. )

Carsten

> -----Original Message-----
> From: Hanson Char [mailto:hanson_char@yahoo.com] 
> Sent: Thursday, July 22, 2004 2:26 PM
> To: 'Turbine JCS Developers List'
> Subject: Cache Memory Guard
> 
> If too much stuff is put into a Java caching system too fast, 
> one may run into the JVM out-of-memory problem.
> 
> One idea is that every time there is a "put" operation (which 
> is the only operation that may increase the memory usage by 
> the caching system), the caching system checks if the current 
> JVM memory usage is over a particular threshold, and if so 
> temporarily disable the "put" by making it a no-op.
> 
> Something like:
> 
>         static final float MEMORY_USAGE_THRESHOLD_PERCENT = 70.0F;
>         ...
>         // Method of putting stuff to the cache
>         public Serializable put(Serializable stuff) {
>                 Runtime rt = Runtime.getRuntime()
>                 double mFree = rt.freeMemory();
>                 double mMax = rt.maxMemory();
>                 double mTotal = rt.totalMemory();
>                 double usage = (mMax - mTotal + mFree) / mMax * 100
> 
>                 if (usage > MEMORY_USAGE_THRESHOLD_PERCENT)
>                         return null;    // cache "put" 
> temporarily disabled
>                 // normal put
> 
>                 ...
>         }
> 
> 
> With such measures, if there was a out-of-memory problem, it 
> still wouldn't be caused directly by the caching system.
> 
> Good idea ?
> 
> Regards,
> Hanson
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: Cache Memory Guard

Posted by Aaron Smuts <as...@yahoo.com>.
Such a limit is a good idea.  We might want such
governors in the abstract memory cache and in the
abstract disk cache.  They should be configurable. 
The indexed disk cache uses memory for keys.  You can
set a maximum number of keys, but this isn't
absolutely safe.

The maxMemory method is jdk 1.4 specific, so whatever
we do will have to be in the 1.4 src directory.  Ugh.

I'm not sure how to put something like this in given
our src split.


Aaron

--- Hanson Char <ha...@yahoo.com> wrote:
> If too much stuff is put into a Java caching system
> too fast, one may run
> into the JVM out-of-memory problem.
> 
> One idea is that every time there is a "put"
> operation (which is the only
> operation that may increase the memory usage by the
> caching system), the
> caching system checks if the current JVM memory
> usage is over a particular
> threshold, and if so temporarily disable the "put"
> by making it a no-op.
> 
> Something like:
> 
>         static final float
> MEMORY_USAGE_THRESHOLD_PERCENT = 70.0F;
>         ...
>         // Method of putting stuff to the cache
>         public Serializable put(Serializable stuff)
> {
>                 Runtime rt = Runtime.getRuntime()
>                 double mFree = rt.freeMemory();
>                 double mMax = rt.maxMemory();
>                 double mTotal = rt.totalMemory();
>                 double usage = (mMax - mTotal +
> mFree) / mMax * 100
> 
>                 if (usage >
> MEMORY_USAGE_THRESHOLD_PERCENT)
>                         return null;    // cache
> "put" temporarily disabled
>                 // normal put
> 
>                 ...
>         }
> 
> 
> With such measures, if there was a out-of-memory
> problem, it still wouldn't
> be caused directly by the caching system.
> 
> Good idea ?
> 
> Regards,
> Hanson
> 



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Cache Memory Guard

Posted by Hanson Char <ha...@yahoo.com>.
If too much stuff is put into a Java caching system too fast, one may run
into the JVM out-of-memory problem.

One idea is that every time there is a "put" operation (which is the only
operation that may increase the memory usage by the caching system), the
caching system checks if the current JVM memory usage is over a particular
threshold, and if so temporarily disable the "put" by making it a no-op.

Something like:

        static final float MEMORY_USAGE_THRESHOLD_PERCENT = 70.0F;
        ...
        // Method of putting stuff to the cache
        public Serializable put(Serializable stuff) {
                Runtime rt = Runtime.getRuntime()
                double mFree = rt.freeMemory();
                double mMax = rt.maxMemory();
                double mTotal = rt.totalMemory();
                double usage = (mMax - mTotal + mFree) / mMax * 100

                if (usage > MEMORY_USAGE_THRESHOLD_PERCENT)
                        return null;    // cache "put" temporarily disabled
                // normal put

                ...
        }


With such measures, if there was a out-of-memory problem, it still wouldn't
be caused directly by the caching system.

Good idea ?

Regards,
Hanson

Re: EventQueues and Threads

Posted by Aaron Smuts <as...@yahoo.com>.
It would also be good if we could call pause on the
queue taker for a region.  Real time defragmentation
would be easier if I could suspend queue takes for a
moment.

I've got the kinks out of the real time
defragmentation / optimization for the disk cache. 
I'll check it in tonight.

Aaron


	
		
__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: EventQueues and Threads

Posted by Aaron Smuts <as...@yahoo.com>.
One thing that might be nice would be a limit to the
number of items allowed in a queue.  We might want to
jsut start dropping the oldest at a certain point. 
The only problem with this is that remove requests to
auxiliaries can be very important.  However, the
possibility of runnnig out of memory is worse. 

Most appliations cannot perform fast enough to swamp
the cache queues, but I can make a test program do it.

We should have some sort of cap on the queue size and
then just start dropping the eldest when full.  There
is no other good solution.

(We might want to add some parameter like, removeall
fom the auxiliary when then point it reached.  I'm not
sure where this kind of thing should be configured
though.)

Aaron

--- Aaron Smuts <as...@yahoo.com> wrote:
> The queue works nicely as is.  If we make radical
> changes it should be in the experiemental section.
> 
> The problem you are addressing the that each region
> will get its own queue with its own thread.  I guess
> we want to be able to limit the number of threads
> used.
> 
> We could have one thread polling all the queues and
> then giving what it takes to the pooled executor.
> This
> might be the easiest conversion.  
> 
> What exactly do you have in mind.
> 
> By the way, my idea for converting the grouping
> functionality will not work.  I'm going to leave it
> as
> is until we come up with something better.  We
> should
> try to decide what needs to be done before we move
> for
> a release.  
> 
> Aaron
> 
> 
> The problem is that each region will gets its own
> 
> --- Travis Savo <ts...@IFILM.com> wrote:
> > We discussed in the past a Thread Throttle to
> limit
> > the number of Threads
> > for EventQueues.
> > 
> > Really I think the right solution is a Thread
> Pool,
> > (and/or a Runnable
> > Queue). If we convert the EventQueue to a Runnable
> > and pull threads from the
> > pool as they become available (and/or stick the
> > Runnables in a queue for
> > processing, either way we achieve the same effect:
> > The threads, of which
> > there are a limited number, get reused), this
> > eliminates the need for a
> > throttle, and makes much better reuse of Threads,
> so
> > 'keeping it alive for a
> > minute' is no longer necessary: The life of the
> > unused Thread itself can be
> > handled by the Pool.
> > 
> > Does this sound like the right solution to you? Or
> > at least headed in the
> > direction of the right solution?
> > 
> > I just wanted to check with you before I start
> down
> > a path that won't lead
> > to everyone's consent.
> > 
> > -Travis Savo <ts...@ifilm.com>
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > turbine-jcs-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > turbine-jcs-dev-help@jakarta.apache.org
> > 
> > 
> 
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Vote for the stars of Yahoo!'s next ad campaign!
>
http://advision.webevents.yahoo.com/yahoo/votelifeengine/
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> turbine-jcs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> turbine-jcs-dev-help@jakarta.apache.org
> 
> 



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: EventQueues and Threads

Posted by Aaron Smuts <as...@yahoo.com>.
The queue works nicely as is.  If we make radical
changes it should be in the experiemental section.

The problem you are addressing the that each region
will get its own queue with its own thread.  I guess
we want to be able to limit the number of threads
used.

We could have one thread polling all the queues and
then giving what it takes to the pooled executor. This
might be the easiest conversion.  

What exactly do you have in mind.

By the way, my idea for converting the grouping
functionality will not work.  I'm going to leave it as
is until we come up with something better.  We should
try to decide what needs to be done before we move for
a release.  

Aaron


The problem is that each region will gets its own

--- Travis Savo <ts...@IFILM.com> wrote:
> We discussed in the past a Thread Throttle to limit
> the number of Threads
> for EventQueues.
> 
> Really I think the right solution is a Thread Pool,
> (and/or a Runnable
> Queue). If we convert the EventQueue to a Runnable
> and pull threads from the
> pool as they become available (and/or stick the
> Runnables in a queue for
> processing, either way we achieve the same effect:
> The threads, of which
> there are a limited number, get reused), this
> eliminates the need for a
> throttle, and makes much better reuse of Threads, so
> 'keeping it alive for a
> minute' is no longer necessary: The life of the
> unused Thread itself can be
> handled by the Pool.
> 
> Does this sound like the right solution to you? Or
> at least headed in the
> direction of the right solution?
> 
> I just wanted to check with you before I start down
> a path that won't lead
> to everyone's consent.
> 
> -Travis Savo <ts...@ifilm.com>
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> turbine-jcs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> turbine-jcs-dev-help@jakarta.apache.org
> 
> 



	
		
__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org