avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Treyger <alex_trey...@yahoo.com>
Subject Re: org.apache.excalibur.event.command package
Date Sun, 27 Oct 2002 07:48:18 GMT
In my environment, it takes time and IO for a command
to be processed.
This is why I would like to use multiple threads to
run different commands from the same source
simultaneously. For this reason, I need commands to be
pulled from a Source one in a time.

To achieve this, I would like to register multiple
instances of a Pipeline (all using the same Source
object) with one AbstractThreadManager.

I have two problems in a AbstractThreadManager as it
is now: 

1. PipelineRunner.run()

pulls all commands in one call:

handler.handleEvents( sources[ i ].dequeueAll() );

I would prefer to be able to use a Runner that pulls
only one command in a time. This would allow another
threads to pull and process another command from the
same source at the same time. Of course, it makes
sense only in a case when it takes time to process
command, and only if such commands wait for IO.

2. register() uses  PipelineRunner (which pulls all
commands from Source in one call), and there is no
easy way to use another Runner instead; a different
Runner is needed for the reason #1.


Runner interface, that I introduced, has two
additional methods:

Object getType();

so that all pipelines that use the same Source, can be
deregistered in one call by type.

boolean isAvailable();

Using this call in AbstractThreadManager may prevent
running the same runner on multiple threads (i.e.
using more then one thread for the same Runner in case
when it runs for a long-long time):

                    while( i.hasNext() )
                    {
                        Runner nextRunner =
(Runner)i.next();
                        ThreadControl control = null;

                        // This does not prevent, but
often avoids
                        // running the same runner on
multiple threads

// INSERTED if
                        if( nextRunner.isAvailable() )
                        {
                            while( control == null )
                            {
                                try
                                {
                                    control =
m_threadPool.execute( nextRunner );
                                }
                                catch(
IllegalStateException e )
                                {
                                    // that's the way
ResourceLimitingThreadPool reports
                                    // that it has no
threads available, will still try
                                    // to go on,
hopefully at one point there will be
                                    // a thread to
execute our runner

                                    if(
getLogger().isWarnEnabled() )
                                    {
                                       
getLogger().warn( "Unable to execute runner (If out of
threads, "
                                                      
   + "increase block-timeout or number of threads "
                                                      
   + "per processor", e );
                                    }
                                }
                            }

                            m_controls.add( control );
                        }
                    }



Thanks,
Alex


--- Berin Loritsch <bloritsch@apache.org> wrote:
> Alex Treyger wrote:
> > Hi Berin and Peter,
> > 
> > My name is Alex; I am working on a project that is
> > similar to the event, but my commands can't be
> > processed quicker than in 10-20 sec. Therefore, I
> need
> > to have more then one thread working from the same
> > queue. Also, I can't use dequeueAll(), since this
> > would serialize command processing.
> 
> You do have more than one thread working from the
> same
> queue.  The ThreadManager has a pool of threads to
> work
> with.  You can set it up to have a certain ratio of
> threads
> to processors.  That way if you have eight threads
> per
> processor set, and you have two processors, the
> commands
> will be executed within sixteen threads.
> 
> The default is one thread per processor--which on a
> one
> processor machine is only one thread.
> 
> > To achieve my goals, I moved ImmediateRunner from
> > AbstractThreadManager to outside, and introduced a
> few
> > interfaces. My new classes, that are versions of
> > yours, I put in sub-package medium.
> 
> What are you wanting to accomplish with the
> interfaces?
> 
> > It make more sense to me to pass Runner (with
> pipeline
> > inside)  instead of Pipeline to ThreadManager,
> since
> > the latter one does not care about pipelines; it
> needs
> > to execute something, that' all. For
> compatibility, I
> > did not remove
> > 
> > register( EventPipeline pipeline )
> > 
> > method.
> 
> No.  The reason is quite simple.  The EventPipeline
> does
> not have to be a CommandManager.  It can be
> anything.  It
> stems from the SEDA package, and is focussed on
> event
> pipelining.
> 
> Please post any questions, etc. to either the user
> list
> or the developer list so I don't have to answer the
> same
> questions over and over.
> 
> 
> > All these new classes, modified classes, as well
> as
> > the rest of classes from the package, are in a
> tar.gz
> > 
> > Please, let me know what you think.
> > 
> > 
> > Thanks,
> > Alex Treyger
> > 
> > PS.
> > 
> > 1. In case you like the change, feel free to
> improve
> > or rename classes.
> > 
> > 2. I do not know policy, so I added my name in all
> > classes I modified.
> > 
> > 3. I added
> > 
> > throw new RuntimeException(e)
> > 
> > in a catch after
> > 
> >  ( (Command)element ).execute();
> > 
> > in CommandManager.
> 
> Why?  where do you expect that RuntimeException to
> be caught?
> Are you sure that it doesn't kill the thread that is
> monitoring
> the queues?
> 
> 
> > 4. Should CommandManager be renamed to a
> > CommandProcessor?
> 
> I was following an XXXmanager idiom.  It could be,
> but I really
> don't see the advantage.
> 
> 
> -- 
> 
> "They that give up essential liberty to obtain a
> little temporary safety
>   deserve neither liberty nor safety."
>                  - Benjamin Franklin
> 


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message