# Round Trip Time of a Service Request The Round Trip Time (RTT) of a network is the time taken from sending a packet to receiving the acknowlegement. We are also interested in factoring in the size of the data being sent over the network and the delay caused by the service processing the request. ```math total_delay = forward_network_delay + service_delay + reverse_network_delay ``` ## Network delay Time to send complete payload over network network_delay = time delay from first byte leaving source to final byte arriving at destination If we ignore the OSI L6 protocol (e.g. HTTP, FTP, Tsunami) then we are modelling a chunk of data moving along a wire. The network delay is then: ``` network_delay = latency + (time difference from start of the data to the end of the data) ``` ### Latency The latency (or propagation delay) of the network path is the time taken for a particular bit of data to get from one end to the other. If we are just modelling one wire (with no switches) then this can be modelled using: latency = distance / speed For optical fibre (or even an eletric wire), the speed naively would be the speed of light. In fact, the speed is slower than this (in optical fibre this is because of the internal refraction that occurs, which is different for different wavelengths). According to http://www.m2optics.com/blog/bid/70587/Calculating-Optical-Fiber-Latency the delay (1/speed) is approximately 5 microseconds / km ``` if distance is in m delay is in s/m latency is in s then latency = distance * 5 / 1E9 ``` (this matches MJB's "propogation_delay" formula) Normally we would just measure the latency of a link. Most real-life connections comprise many network links and many switches, each of which introduces some latency. ### Data delay The time difference from start of the data to the end of the data (or "data delay" for want of a better term) is dependent on the bandwidth of the network and the amount of data. ``` if data_size is in Bytes bandwidth is in Mb/s data_delay is in s then data_delay = data_size * 8 / bandwidth * 1E6 ``` The data_size naively is the size of the data you want to send over the network (call this the "file_size"). However, the data is split into packets and each packet has a header on it so the amount of data going over the network is actually more than the amount sent. ``` let packet_size = packet_header_size + packet_payload_size then data_size = (packet_size / packet_payload_size) * file_size or data_size = (packet_size / packet_size - packet_header_size) * file_size ``` ### Total delay ``` delay = latency + data_delay = (distance * 5 / 1E9) + {[(packet_size / packet_size - packet_header_size) * file_size] * 8 / bandwidth * 1E6} ``` ### Effect of Protocol The choice of protocol has a large effect in networks with a high bandwidth-delay product. In data communications, bandwidth-delay product is the product of a data link's capacity (in bits per second) and its round-trip delay time (in seconds). The result, an amount of data measured in bits (or bytes), is equivalent to the maximum amount of data on the network circuit at any given time, i.e., data that has been transmitted but not yet acknowledged. TCP for instance expects acknowledgement of every packet sent and if the sender has not received an acknowledgement within a specified time period then the packet will be retransmitted. Furthermore, TCP uses a flow-control method whereby the receiver specifies how much data it is willing to buffer and the sending host must pause sending and wait for acknowledgement once that amount of data is sent. ## Service Delay