On Nov 18, 2007 5:12 AM, Maciek Stachowiak <[EMAIL PROTECTED]> wrote:
> Hello Tristan and everyone,

Hi Maciek, I am Trustin.  :)

> Firstly I wanted to say that what you guys have here is great. About a year
> ago I was looking for a NIO framework of some kind and had no luck finding
> anything so I ended up writing my own. Unfortunatly, there were many
> problems and fringe cases that plagued my code so I was really relieved when
> I found Mina.

Glad that you are here finally, and I hope you enjoy this framework.

> Basically I'm writing a server with many continuous connections open at the
> same time (approx 7,000, eventually more), I need every connection to be
> able to send a request and receive a response from the server within a
> reasonable amount of time. My old framework would receive any requests and
> queue them up. A separate process "SchedulingThread" would run and pass off
> any scheduled jobs in a roundrobin fashion into a "WorkerThreads" queue
> (pool of perhaps 10 "WorkerThreads"). The "WorkerThreads" would then process
> the job and queue up any responses. Being a relative novice when it comes to
> server design I figured this kind of model would allow me to get the most
> out of my machines resources. Anyway, I'm sorta trying to mimic (to a
> degree) this kind of design using MINA...
>
> Since I haven't found an example of this kind of "multi thread" setup I'm
> working off the "Configuring Thread Model" doc in the "Advanced Topic"
> section. I'm also using release 1.1.4 (would you recommend switching to
> 2.0?)

Isn't it an acceptor with an ExecutorFilter inserted?  Am I missing something?

> Anyway, this is what I currently have... obviously I sorta lost at the
> moment... :)
>
> //I'm still somewhat confused regarding what the executorservice is suppose
> to do?
> ExecutorService executor = ...;
>
> IoAcceptor acceptor = new
> SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
> executor.newCachedThreadPool());
> IoAcceptorConfig config = new SocketAcceptorConfig();
>
> //Disabled ThreadModel as suggested in the documentation
> config.setThreadModel(ThreadModel.MANUAL);
>
> DefaultIoFilterChainBuilder chain = config.getFilterChain();
> chain.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory()));
> chain.addLast("threadPool", new
> ExecutorFilter(executor.newCachedThreadPool());
>
> //WorkerHandler extends IoHandlerAdapter, should I be doing something here
> (implementing runnable in the WorkerHandler?) since this is the workhorse of
> the server and I'll probably want mutliple threads running an processing...
> acceptor.bind(new InetSocketAddress(PORT), new WorkerHandler(), config);
>
> //How would I unbind?
> acceptor.unbind(...);
> executor.shutdown();
>
> If anyone could point me in the right direction or better yet show me an
> example I would really appreciate it... thanks ahead of time... and you guys
> have something really cool here...

If you added an ExecutorFilter, you don't need to use an extra thread
pool for your tasks.  However, ExecutorFilter in 1.x always maintains
the order of received messages, which means one connection uses only
one thread at the same time.  To disable event ordering:

1) Use MINA 2.0 and UnorderedThreadPoolExecutor
2) Use MINA 1.x and implement your own IoFilter.
3) Use MINA 1.x, don't use ExecutorFilter but call executor in your
IoHandler implementation.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Reply via email to