## Calculation supporting Figure 1.17 in Peterson and Davie¶

• The curvature we see in the figure in the book is due to the log-log scale
• Really, all the plots are linear, which you can see from the equation, where the only variable in each plot is RTT
• i.e., y = x + C1 + C2, where y is latency, x is RTT, C1 is size/bw, and C2 is queue
• I've plotted each below on a linear scale and a log scale

### establish the different bandwidths, sizes, and rtts¶

In [81]:
# bandwidth in bits/sec
bws = [1.5e6, 10e6]

# object size in bits
sizes = [1e6*8, 2e3*8, 1*8]

# RTT in ms
rtt = range(1,101)

# ignoring queue since it's constant for everything

# this list will hold a list of latencies (i.e., latency[0] is a list of latencies for the 1MB/1Mbps case)
for i in range(0,6):
latency.append([])


## equation: latency = rtt + size/bw + queue¶

• it's a straight, but not quite flat line, because it's dominated by the bandwidth (size/bw >> rtt)
• i've also plotted the baseline latency = RTT, which is basically 1 to 1
In [82]:
bw = bws[0]
size = sizes[0]
latency[0] = []
oneToOne = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[0].append(rtt[idx] + size/bw*1000)
oneToOne.append(rtt[idx])

In [83]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()


### add 1MB and 10 Mbps¶

• here you can see that the higher bathdwidth results in a much lower initial latency, but the transmission time (size/bw) is still dominant
• the little curl at the end is the artifact of approaching 10^3 on a log scale...
In [84]:
bw = bws[1]
size = sizes[0]
latency[1] = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[1].append(rtt[idx] + size/bw*1000)

In [85]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()


• here the initial latency is approaching zero because we're getting the 2KB packet onto the line quickly
• you can also see that we start to approach the 1 to 1 line in this case, because we get rid of the packet so quickly
In [86]:
bw = bws[0]
size = sizes[1]
latency[2] = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[2].append(rtt[idx] + size/bw*1000)

In [87]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()


In [88]:
bw = bws[1]
size = sizes[1]
latency[3] = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[3].append(rtt[idx] + size/bw*1000)

In [89]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()


### here I've dropped the first two (the 1MB plots) and scaled the axes so you can see better¶

In [90]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,120,step = 10));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,120,step = 10));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()


### add 1B and 1.5Mbps and 10Mbps, since I think you get the point¶

In [91]:
bw = bws[0]
size = sizes[2]
latency[4] = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[4].append(rtt[idx] + size/bw*1000)

bw = bws[1]
size = sizes[2]
latency[5] = []

for idx in range(0,len(rtt)):
# multiply size/bw by 1000 to convert from s to ms
latency[5].append(rtt[idx] + size/bw*1000)

In [92]:
import matplotlib.pyplot as plt
import numpy as np

plt.figure(1, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(latency[4], label = '1B/1.5Mbps', color='C4');
plt.plot(latency[5], label = '1B/10Mbps', color='C5');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[0], label = '1MB/1.5Mbps', color='C0');
plt.plot(latency[1], label = '1MB/10Mbps', color='C1');
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(latency[4], label = '1B/1.5Mbps', color='C4');
plt.plot(latency[5], label = '1B/10Mbps', color='C5');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,6000,step = 500));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()

plt.figure(2, figsize = (12,6))

plt.subplot(1,2,1)
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(latency[4], label = '1B/1.5Mbps', color='C4');
plt.plot(latency[5], label = '1B/10Mbps', color='C5');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,120,step = 10));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.title('linear')
plt.legend();

plt.subplot(1,2,2)
plt.plot(latency[2], label = '2KB/1.5Mbps', color='C2');
plt.plot(latency[3], label = '2KB/10Mbps', color='C3');
plt.plot(latency[4], label = '1B/1.5Mbps', color='C4');
plt.plot(latency[5], label = '1B/10Mbps', color='C5');
plt.plot(oneToOne, label = 'latency = RTT', color='C6')
plt.yticks(np.arange(0,120,step = 10));
plt.xlabel('RTT')
plt.ylabel('latency (ms)')
plt.yscale('log')
plt.xscale('log')
plt.title('log')
plt.legend();

plt.tight_layout()