In my application, i use mina 1.1 version.
Now i do some perfermance test. Below is my test case.
loop (50) {
client send message to server. (500 client one time).
sleep 1s.
}
And in the executing, the server stop response. It just hang. However,
sometimes it passed the test.
I sniff the network using tcpdump. And i found that the packet is received
by the server machine, but no log output in the code decode part.
So I think it even don't go to the doDecode step. It's very strange, and i
don't know the reason.
Thank you for you advice. Below is the related code.
The code of server side:
public class BIIServer {
private static final int port = 12345;
private static BIIServerSessionHandler handler = new
BIIServerSessionHandler();
public static void main(String[] args) throws Exception
{
try {
Executor executor = Executors.newCachedThreadPool();
SocketAcceptor acceptor = new
SocketAcceptor(Runtime.getRuntime().availableProcessors(),
executor);
ExecutorThreadModel model = ExecutorThreadModel.getInstance
("BIIServer");
model.setExecutor(executor);
acceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter(new BIProtocolCodecFactory(true)));
acceptor.getFilterChain().addLast("threadpool", new
ExecutorFilter(executor));
SocketAcceptorConfig config = new SocketAcceptorConfig();
config.setReuseAddress(true);
acceptor.bind(new InetSocketAddress(port), handler, config);
System.out.println("Server now listening on port: " + port);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The code of client side:
public UIDMessage orderUID(OrderUIDMessage message) {
IoSession session;
Object lock = new Object();
for ( ; ; ) {
try {
ConnectFuture future = connector.connect(new
InetSocketAddress(host, port), handler, cfg);
future.join();
session = future.getSession();
session.setAttribute("lock", lock);
break;
} catch (RuntimeIOException ex) {
} catch (InterruptedException e) {
}
}
session.write(message);
synchronized (lock) {
try {
while (session.getAttachment() == null) {
lock.wait(); <- I use this to
ensure i receive the result message. But due to the problem, it was made to
wait indefinitely.
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
UIDMessage UID = (UIDMessage)session.removeAttribute("");
sessionMap.put(UID.getUid(), session);
return UID;
}