# Neil Carpenter's Blog

Forefront products, WSUS, Security Incident Response, and whatever else comes up.

# Blogs

### Quick Figuring Optimal TCP Window Size

• Comments 2
• Likes
There generally isn't a single correct way to figure out the optimal TCP window for an interface since you're probably connecting to different hosts across different links at different latencies; however, you can roughly guess what the optimal window would be if you're only primarily worried about your communication with one other host (or, perhaps, one other site).  First, you'll need to know the latency and the throughput available between you & the remote host.  To get the latency, ping the remote host and take the average response time.  For the throughput, take the slowest link between you & the remote host (ie, you might both be connected to 100Mb/s Ethernet, but there is a 1.5Mb/s WAN link between).  If the slowest link is asymmetrical, use the faster of the two speeds -- for example, on an ADSL connection that was rated as 1.5Mb/s down and 384Kb/s up, use the 1.5Mb/s speed.  (If both ends are on DSL, use the lower speed as this will always be the limiting factor.)

Once we've got these two numbers, the normal formula used to calculate optimal TCP window is bandwidth * latency = window.  Remember that throughput is measured in bits per second whereas our TCP window is going to be configured in bytes per second.  Divide the throughput by 8 to convert bits per second to bytes per second.

So, if we were using a 1.5Mb/s ADSL link with 70ms of latency, our calculation would look something like this:
(1.5*1024*1024/8)bytes/second  *  .07seconds = ~13763bytes
So, on this link, a 13KB TCP window would work well.  Since the default TCP window for Windows 2000/XP/2003 is 16K (or more), there would be no need to change the window on this client; however, if either the throughput or the latency was higher, we would probably benefit from a change.
Comments
• I took your formula Neil and put it into a command line c++ quick app.

Instructions:
1. Use VS6
2. New -> Win32 Console App -> Hellow World
3. Paste the code below in.

Disclaimer:
It worked for me. Well except that it might not round up correctly (but that is just 1 byte). :)

Thanks for your blog.

// tcpwindow.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
float pingRTT;
float bandwidth;

char* pingExample = "c:\\>ping slow-msg-51\n\n\tReply from 17.54.12.19: bytes=32 time=176ms TTL=56\n\tReply from 17.54.12.19: bytes=32 time=114ms TTL=56\n\tReply from 17.54.12.19: bytes=32 time=117ms TTL=56\n\tReply from 17.54.12.19: bytes=32 time=171ms TTL=56\n";
char* pingExample2 = "\n\tPing statistics for 17.54.12.19:\n\t Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\n\tApproximate round trip times in milli-seconds:\n\t Minimum = 114ms, Maximum = 176ms, Average = 144ms\n\n";

printf("===================================\n");
printf(" The TCPWindow Size Tool\n");
printf("===================================\n");
printf("\n\n");

printf("STEP 1: Find the RTT:\n");
printf("======================\n");
printf("Example: \n");
printf("\t");
printf("%s",pingExample);
printf("%s",pingExample2);
printf("Note ---> Approximate round trip times in milli-seconds:\n\t ... Average = 144ms\n\n");
printf("\n\n");
printf("========================================================\n");
printf("What is the Approximate round trip times for your issue?\n");
printf("========================================================\n");
printf(" Action: Type in the seconds value (if rtt was 144 then enter \".144\")\n and press ENTER\n\n");
printf("RTT Value: ");
scanf("%f",&pingRTT);

printf("\n\n");
printf("STEP 2: State the bandwidth:\n");
printf("==============================\n");
printf("Example: \n\n");
printf("\t");
printf("This is the WAN bandwidth. An example could be 1.44, 5, 10, 45, etc...\n");
printf("\n\n");
printf("=====================================================\n");
printf("What is the the available bandwidth of your WAN link?\n");
printf("=====================================================\n");
printf(" Action: Type in the value (i.e. 1.5) and press ENTER\n\n");
printf("Value: ");
scanf("%f",&bandwidth);
printf("\n\n");

printf("You have specified: %f as the RTT.\n",pingRTT);
printf("You have specified: %f for the bandwidth.\n",bandwidth);

printf("\n\n");
printf("STEP 3: Do the numbers:\n");
printf("==============================\n");
printf("Step1: ([BANDWIDTH]*1024*1024/8)bytes/second * [ROUND TRIP] = [TCP WINDOW]\n\n");
printf("Step2: (%f*1024*1024/8)bytes/second * (%f) = [TCP WINDOW]\n\n",pingRTT,bandwidth);
int step3;
step3 = (pingRTT * 1024*1024/8);
printf("Step3: (%f) * (%f) = [TCP WINDOW]\n\n",step3,bandwidth);
float step4;
step4 = step3 * bandwidth;
printf("Step4: %f = [TCP WINDOW]\n\n",step4);
printf("Step4: TCPWindowSize = %d\n\n",int(step4));

return 0;
}

• Glad you found it useful! I'd like to start getting more network-oriented stuff out here...