In this post: A detailed, step-by-step guide demonstrating the steps I use to solve a problem similar to one encountered in my CS 372 Intro to Networking class.
A client’s browser sends an HTTP request to a website. The website responds with a handshake and sets up a TCP connection. The connection setup takes 2.5 ms, including the RTT. The browser then sends the request for the website’s index file. The index file references 2 additional images, which are to be requested/downloaded by the client’s browser. How much longer would non-persistent HTTP take than persistent HTTP?
Suppose they want the answer in milliseconds rounded to 2 decimal places.
You can get fancy with writing out each and every request (and this is what they’ll show in the worksheet), but there’s a faster way, especially if the number of referenced objects is more than a few.
Step 1: Count the total number things you’re getting, ie: 1 index file + 3 images = 3. That’s your N value.
index.html + image1.jpg + image2.jpg = 3 things total
Step 2: For non-persistent HTTP, your answer will be the result of N x 2.
3 x 2 = 6 connections needed for non-persistent HTTP
(That’s because for each and every item you request, you also need to request a TCP connection.)
- TCP request
- index.htm request
- TCP request
- image1.jpg request
- TCP request
- image2.jpg request
Step 3: For persistent HTTP, do N+1
3 + 1 = 4 connections needed for persistent HTTP
(That’s because you only need to connect once, and then request all the things you want.)
- TCP request
- index.htm request
- image1.jpg request
- image2.jpg request
Step 4: Now you have:
6 connection requests for non-persistent HTTP
4 connection requests for persistent HTTP
Step 5: Find the difference.
6 - 4 = 2
Non-persistent HTTP needs 2 more connections than persistent.
Step 6: Multiply that difference by how long each connection takes to set up.
2 x 2.5 milliseconds = 5 milliseconds.
Double-check your rounding and units! You might be asked to give this in seconds instead of milliseconds.
In summary
- Sum the things (index file and images) to get N
- Non-persistent HTTP = N x 2
- Persistent HTTP = N + 1
- Find the difference
- Multiply the difference by how long a round trip takes