title: What is the ideal buffer/packet size to send over the network?
body: <p>Right now i have an application that is sending a file over the network. I am at the stage i need to optimize the app so that the transfer speed is ideal.</p>
  
  <p>I have a super professional looking graff showing my situation:<a href="https://i.stack.imgur.com/hFkDm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hFkDm.png" alt="enter image description here"></a></p>
  
  <p>Y - Sending time.
  X - Buffer size.</p>
  
  <p>The Y is the sending time, and the X is the buffer/packet size.
  Has you can see, from my experiments i have noticed that if the buffer size is to small the sending time is to slow, and if the buffer size is to big the sending time is to high.
  There is a sweet spot where the buffer size seems to be ideal. That is where i need help from some people that hopefully have more experience in networking. </p>
  
  <p>Right now this is how i am sending the buffer.</p>
  
  <pre><code> for (int i = 0; i &lt; NoOfPackets; i++)
   {
         if (totalFileLength &gt; netBufferSize)
         {
            currentPacketLength = netBufferSize;
            totalFileLength = totalFileLength - currentPacketLength;
         }
         else
            currentPacketLength = totalFileLength;
  
         SendingBuffer = new byte[currentPacketLength];
         compressed.Read(SendingBuffer, 0, currentPacketLength);
         netWorkStreamVar.Write(SendingBuffer, 0, currentPacketLength);
    }
  </code></pre>
  
  <p>Right now the fastest sending buffer size i have encountered is <strong>1024 * 256</strong>. 
  Question list: </p>
  
  <p><strong>How can i determine that sweet spot?</strong>(where the sending buffer size is ideal) </p>
  
  <p>Is is determined by the file type?  </p>
  
  <p>Does it depend on my network configuration.  </p>
  
  <p>Is there an "industry" standard?  </p>