hi

I have some question related to the threading model used by MINA. I've read the FAQ entry titled "Do I need to make my IoHandler thread- safe?", but was still a bit confused. So I've built a simple sample application.

The server checks how many threads are executing the code of the messageReceived method of the IoHandler. The client sends a lot of messages to the server. To simulate a long running task, the messageReceived method of the server contains a Thread.sleep.

Without adding any filter (in particular the ThreadPoolFilter, of course), the messageReceived method of the server IoHandler is executed by just one thread at a time (in fact, always the same thread). The overall throughput of the server is low (the server was sleeping most of the time...).

After adding a ThreadPool filter the situation changed. The IoHandler messageReceived method is called by more than one thread at a time (server-side). However, the method is called by only one thread at a time for a particular session.

What I find a bit strange is that on the server-side, there is only one IoHandler for all the sessions. Therefore it is unsafe to use any instance variables inside handlers (that is, without proper synchronization). I guess that's what is meant with "shared resource" in the FAQ. To achieve thread safety, the state should be stored as session attributes (correct?) or the access would have to be properly synchronized.

On the client side, it is possible to specify a separate IoHandler for each session. Wouldn't it be more natural to have the possibility to store state in the handler itself? On the server, this would require to have a separate IoHandler for each session. What do you think?

Simon

Reply via email to