title: TCP transfer in Java is VERY slow
body: <p>I am doing a program to saturate a link for performance testing in my networking lab, I tried different things, from changing Send and Receive buffers, creating a file and reading it, creating a long array and sending it through the socket all at once: OutputStream.write(byte[])</p>
  
  <p>The array is 1000000 positions length, when I sniff the network traffic, according to the sniffer, the packets have "Data (1460 bytes)" which make me supose that I'm not sending byte by byte.</p>
  
  <p>The bandwidth used is about 8% of the 100Mbps.</p>
  
  <p>I post the relevant code as there is some interaction between client and server which I don't think is relevant:</p>
  
  <p>Client:</p>
  
  <pre><code>int car=0;
  do {
      car=is.read();
      //System.out.println(car);
      contador++;
  } while(car!=104);
  
  Server:
  
  byte dades[]=new byte[1000000];
  FileInputStream fis=null;
  try {
      FileOutputStream fos = new FileOutputStream("1MB.txt");
      fos.write(dades);
      fos=null;
      File f = new File("1MB.txt");
      fis = new FileInputStream(f);
      step=0;
      correcte=true;
      sck = srvSock.accept();
      sck.setSendBufferSize(65535);
      sck.setReceiveBufferSize(65535);
      os = sck.getOutputStream();
      is = sck.getInputStream();
  }
  
  ...
  
  BufferedInputStream bis = new BufferedInputStream(fis);
  bis.read(dades);
  for(int i=0;i&lt;100;i++) {
      os.write(dades);
  }
  </code></pre>
  
  <p>In this case I put the last idea I had, to create a file with a million positions byte array and then read this file and write to the socket, before this idea I was sending the byte array.</p>
  
  <p>Another thing which make me believe this is not a byte by byte sending is that in a quad core computer the client uses 25% CPU and uses around 8% of the bandwidth, and in an old computer which is single core (AMD Athlon) it uses 100% of the CPU and just 4% of the bandwidth. The server is not so CPU intensive.</p>
  
  <p>Any ideas??? I feel a little lost right now...</p>
  
  <p>Thanks!!!</p>