IoThreadPoolFilter f = (IoThreadPoolFilter)
reg.getIoAcceptor(TransportType.SOCKET).getFilterChain().get("threadPool");
f.setMaximumPoolSize(10);

I discovered that this piece of code gives me "NullPointerException", I have no FilterChain applied to the Acceptor and in my Eclipse debugger I can see:

"registry.getAcceptor(TransportType.SOCKET).getFilterChain()" is null probably because I didn't create any filter...is it right ? And if not is there any tutorial which explain the use of the Filters or Codecs (I don't use this, I simply created a class which extends IoHandlerAdapter and from there I have overriden the methods I wanted to use like sessionOpened(...) sessionClosed(...) onMessageReceived(...) and from here I started to implement my high level protocol (Direct Connect)

Here it is a little snippet which can make you understand my probably wrong impact on the software:

   @Override
public void messageReceived(IoSession session, Object obj) throws Exception { // I get the message
       String msg = null;
       try {
          // Object is a ByteBuffer
           ByteBuffer buf = (ByteBuffer) obj;
// I get the string from the ByteBuffer decoding with Windows-1252 charset decoder
           msg = buf.getString(decoderCp1252);
           log.debug("Received message was " + msg);
       } catch (Exception _e) {
           // msg is null
           _e.printStackTrace();
       }

   // load plugins and execute
       boolean process = true;
       for (JxHubAbstractPlugin plugin : pluginManager.getPlugins()) {
           boolean tmp = plugin.onMessageReceived(session, msg);
           if (!tmp)
               process = false;
       }
       if (process)
// And finally here it is where I call the method which will dispatch my command // pipeline is a JxHubPipeline a object I have created and that I report after this snippet
           pipeline.dispatchAction(session, msg);

   }


// Here it is the JxHubPipeline structure
JxHubPipeline(JxHubDbPoolFactory, ConcurrentHashMap<String, IoSession>, JxHubConfiguration, JxHubPluginManager) // it will understand what kind of message it is and it will forward to the right method
dispatchAction(IoSession, String)
processUserIp(IoSession, String)
processOpForceMove(IoSession, String)
processGetInfo(IoSession, String)
processConnectToMe(IoSession, String)
processMyInfo(IoSession, String)
processGetNickList(IoSession, String)
processSupports(IoSession, String)
processKey(IoSession, String)
processChat(IoSession, String)
processValidateNick(IoSession, String)
processOperatorCommand(IoSession, String)
processMyPass(IoSession, String)
processRevConnectToMe(IoSession, String)
processTo(IoSession, String)
processSearch(IoSession, String)
processSr(IoSession, String)

I'm stopped ! I don't know where to look. I think there's too little documentation or too few examples for Mina, I think more complex samples are needed !
Regards, Alex

Niklas Therning wrote:

No, the number of threads in your thread pool does not limit the number of concurrent clients. That's actually one of the big benefits of using MINA. Since everything is event based you can use a small number of threads to handle a larger number of connections.

Please, try to set the max pool size to a small number (5-10 maybe) and see if this has any impact on the performance.

/Niklas

Alessandro Torrisi wrote:

But in this way I will limit users max number in the hub server I think...
Is there any way to have a significant increase of performance ?

Regards,
Alex.


Niklas Therning wrote:

Alessandro Torrisi wrote:

Hi ! I'm developing a free and opensource Direct Connect software (P2P server). Now that protocol implementation is quite complete I'm testing with lot of connections. When connections are made in a concurrent way (50-100 a time), the server seems to be blocked... Can I do something to improve performance, adjusting some parameter or applying some programming pattern directly on Mina ? I've listened about Thread Pools on SocketAcceptor and IoThreadPool but I didn't find any tutorial or documentation, is it possible to directly configure these ones ?




Yes. By default the maximum thread pool size equals Integer.MAX_VALUE. It can be changed but this has changed bewteen MINA 0.8 and 0.9.

In 0.8, when using SimpleServiceRegistry, you can configure the maximum pool size like this:

IoThreadPoolFilter f = (IoThreadPoolFilter)
reg.getIoAcceptor(TransportType.SOCKET).getFilterChain().get("threadPool");
f.setMaximumPoolSize(10);

In 0.9 its not that easy since the ThreadPoolFilter used by SimpleServiceRegistry isn't accessible until a session has been created. You could try to extend SimpleServiceRegistry and configure the protected threadPoolFilter yourself:

public class MyServiceRegistry extends SimpleServiceRegistry {
    public MyServiceRegistry() {
        super();
        threadPoolFilter.setMaximumPoolSize(10);
    }
}

And then instead of using SimpleServiceRegistry you use MyServiceRegistry.

Both of these approaches will use a thread pool of at most 10 threads.

HTH
/Niklas





Reply via email to