Hello,
Please help, as this is too strange to be true...
I'm comparing two implementations of the most basic socket server - it
listens for a client, and after accepting it just starts reading data from
it.
The first implementation using Java's plain old ServerSocket:
ServerSocket srv = new ServerSocket(80);
Socket s = srv.accept();
InputStream i = s.getInputStream();
byte[] buf = new byte[1024 * 8];
while (true) {
i.read(buf);
}
The Second implementation using MINA 1.1.7 (which so simple that I can paste
it here):
First the Main class:
package test;
import java.net.InetSocketAddress;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
public class Main {
public static void main(String[] args) throws Exception {
// The following two lines don't help
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
IoAcceptor acceptor = new SocketAcceptor();
acceptor.bind(new InetSocketAddress(80), new MyHandler());
}
}
And the IoHandler:
package test;
import org.apache.mina.common.IoHandlerAdapter;
public class MyHandler extends IoHandlerAdapter {
}
I wrote a simple client that connects to the server and pumps continuous
data.
Both client and server run on Amazon's EC2 on Debian Linux instances
(64-bit, Java 1.6). Client is in Europe and server in USA.
*The results:*
Simple Java implementation - 5 Mbps
MINA implementation - 750 Kbps
Tried removing the setUseDirectBuffers lines; tried a simpler threading
model by running the IoHandler on the IoProcessor threads... nothing helps -
MINA is capped at 750 Kbps.
What is going on here?!