I tested the performance of transferring data from a program to another over socket on a single computer, and the speed is 120MBytes/s, is it normal?
My server and client programs are both extremely simple.
And my computer is AMD Athlon X2 4000+, 4G DDR2 667 ram, with windows xp sp3.
My friend said it was slow, and should be faster. But I don’t know how can I improve them, or is there any other libraries I can try to get a better speed?
UPDATE
The server and client programs were both on my own computer, a single computer. The network card will limit the speed or not?
Server.java
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class SimpleServer {
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(6666);
Socket socket = server.accept();
OutputStream output = socket.getOutputStream();
byte[] bytes = new byte[10 * 1024]; // 10K
for (int i = 0; i < bytes.length; i++) { bytes[i] = 12; } // fill the bytes
// send them again and again
while (true) {
output.write(bytes);
}
}
}
Client.java
public class SimpleClient {
public static void main(String[] args) throws Exception {
Socket socket = new Socket("127.0.0.1", 6666);
InputStream input = socket.getInputStream();
long total = 0;
long start = System.currentTimeMillis();
byte[] bytes = new byte[10240]; // 10K
// read the data again and again
while (true) {
int read = input.read(bytes);
total += read;
long cost = System.currentTimeMillis() - start;
if (cost > 0 && System.currentTimeMillis() % 1000 == 0) {
System.out.println("Read " + total + " bytes, speed: " + (total / (1024.0*1024)) / (cost / 1000.0) + " MB/s");
}
}
}
}
Can you give me the output of this program?
on my machine prints
Try sending 32K blocks many times (for at least 2 seconds) and you should get 400 MB/s or more. e.g. at least 10,000 times.
On a very fast machine you can get 1 GB/s on a single client. With multiple clients you might get 8 GB/s.
Here is an example
Making file transfer more efficient Java
If you have a 100 Mb card you can expect around 11 MB/s (bytes per second).
Similarly for 1 Gb ethernet youc an expect around 110 MB/s
For a 10 Gig-E ethernet you might get up to 1 GB/s however you might only get half this unles syour system is highly tuned.