2

When I load a web page that displays, why do I open a new TCP connection for the HTTP requests for each image? Why isn't a single TCP connection reused for the duration of the page load?

fkl
  • 5,412
  • 4
  • 28
  • 68
Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • This is off topic. However, imagine a phone call is the same as a TCP connection. If you need to call someone different (image) you need to make a new phone call. Please review the [Help - On Topic Quetions](http://stackoverflow.com/help/on-topic) – Erik Philips Oct 26 '13 at 06:33
  • Following http://stackoverflow.com/a/12795169/986760 might help to see the picture clearly for those who are confusing pipe lining with multiple tcp connections – fkl Oct 26 '13 at 07:10
  • @ErikPhilips a Fetching another image from the same site doesn't require a new connection. – user207421 Oct 26 '13 at 07:12

3 Answers3

4

I think the browser usually opens multiple connections so that it can load content in parallel. Another possibility is that the server could be closing the connection after it has finished sending an image file and thus forcing the browser to create a new connection.

Arun Taylor
  • 1,574
  • 8
  • 5
2

Browser also incorporates a technique called HTTP pipelining where existing TCP connection is used for multiple HTTP request but the problem is that all the incoming HTTP responses should be in the same order as of the requests sent .

HTTP pipelining :

enter image description here

For more info , visit the page

Subbu
  • 2,063
  • 4
  • 29
  • 42
1

Although most of reasons cited already are true (and i upvoted) i.e. you might need to get different resources via different connections e.g. one loads logo, other loads page data etc. and pipe lining is not always possible, plus it attempts to do things in parallel.

Still, the over head of multiple TCP connections has an impact on http being slower overall. That is why google has been working on speeding it up and the new model http 2.0 will use a single http connection.

Details were posted a few days ago on hacker news and the bench marks are pretty impressive, though it has several other factors such as using lesser number of bytes for protocol over head.

SPDY was the early release by google itself

fkl
  • 5,412
  • 4
  • 28
  • 68
  • Sir, are you saying that for each tab there are may be multiple TCP connections as each webpage in the tab consists of lot resources/content to be downloaded ? – Subbu Oct 26 '13 at 06:57
  • Yes that is exactly the case. Even for a very trivial request, two connections are used, one of which downloads logo separately. – fkl Oct 26 '13 at 06:58
  • Can you give me a practical example where pipelining is used ? webpage for a example ?? – Subbu Oct 26 '13 at 06:59
  • Take a look at this Q&A http://stackoverflow.com/a/12795169/986760 showing two requests by chrome – fkl Oct 26 '13 at 07:02
  • @Subbu I am not sure about your question, pipelining is submitting multiple get requests with in the same connection (rather same packet unless it is fragmented for size). There is still a single tcp connection. What we are talking about above is more than one tcp connection which is indeed used in a single http page fetch. – fkl Oct 26 '13 at 07:04
  • @fayyazki .. Sir I was asking for webpage where all resources/contents are downloaded from the same server , using pipelining .. single TCP connection but multiple HTTP requests – Subbu Oct 26 '13 at 07:15
  • That usually does not happen in practice. For one pipelining is not supported by default in most browsers. Though you can enable it in chrome and see for yourself – fkl Oct 26 '13 at 07:20