I'm trying to measure the performance differences between the plain tcp socket and the SSL socket on my gigE local network. For the plain tcp socket I got close to 100MB/s between my client/server apps. With SSLSocket/SSLServerSocket I could only get transfer speed of 2MB/s from my client to the server. From the handshake debug log,128bit RC4 (SSL_RSA_WITH_RC4_128_MD5) is used for data transfer. Obviously I wouldn't expect SSL socket to be as fast as the plain socket. However, I believe the performance differences should be no more than 2-3X. The code I used for the server is like:
SSLServerSocketFactory sslSrvFact = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket server_socket = (SSLServerSocket) sslSrvFact.createServerSocket(port);
SSLSocket socket = (SSLSocket) server_socket.accept();
input = new BufferedInputStream(socket.getInputStream());
byte[] buf = new byte[size]; // size is set to 8000000 in my test
long c = 0;
try {
while(true) {
int x = input.read(buf);
if (x>=0) {
c += x;
if (c >= size) {
break;
}
}
}
}
catch (IOException e) {
e.printStackTrace();
}
For the client I've:
// connect to server
try {
SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) sslFact.createSocket(server, port);
output = new BufferedOutputStream(socket.getOutputStream());
byte[] out = new byte[size]; // set to 8000000 to match the server side
output.write(out);
output.flush();
}
catch (IOException e) {
e.printStackTrace();
}
For the record all the tests were carried out with jdk1.6 on Fedora 6. Btw I also tested the plain tcp socket coupling with stunnel. The result was much more reasonable (2-3X slower than non-SSL transfer). So I hope someone can help me to track down the root cause of the performance differences.