0

Let's say my browser post a HTTP request to a domain, before this request finish, another different request (by ajax) was send to the same domain. Since the first request still on-going and not yet terminated, will that mean second request will have to wait first request to finish in order to use the persistent connection that being used by first request? If it is, how to prevent this? If I have a long streaming connection in the first request, does that mean second request will need to hang around for long time?

(Let's assume the maximum persistent connection for browser is one. Actually I don't really understand what this "max persistent connection" does. Does it mean when the persistent connection is over the maximum number, the rest of connection will become non-persistent ? Confusing...)

Can anyone explain this?

Sam YC
  • 10,725
  • 19
  • 102
  • 158
  • Which browser are you using and where did you set its "*maximum persistent connection*"? – Bergi Feb 10 '14 at 04:05
  • Seems like this is up to your server architecture on whether your server can process multiple connections at once or whether it must process them one at a time. – jfriend00 Feb 10 '14 at 04:06
  • @Bergi I don't think we can set the max persistent connection, could we? I refer to this wiki page http://en.wikipedia.org/wiki/HTTP_persistent_connection#Use_in_web_browsers – Sam YC Feb 10 '14 at 04:09
  • @GMsoF: Basically every browser does have an option for this in its settings, yes. – Bergi Feb 10 '14 at 04:28

1 Answers1

1

Since the first request still on-going and not yet terminated, will that mean second request will have to wait first request to finish in order to use the persistent connection that being used by first request?

No. The two requests are still asynchronous and in parallel (unless the server limits this).

HTTP Keep Alive only means that they are faster because both requests can use the same connection, especially when pipelining them.

However, if there is no pipelining, the browser could also decide to open a second connection for the second request, instead of waiting for the first request to finish and reusing its connection. See Under what circumstances will my browser attempt to re-use a TCP connection for multiple requests? for details.

I don't really understand what this "max persistent connection" does. Does it mean when the persistent connection is over the maximum number, the rest of connection will become non-persistent?

No. When the limit is reached, new requests will have to wait until a connection from the pool becomes usable again.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Does it mean even when the first request is streaming and occupying the persistent connection for long time, the second request still have chance to get into first persistent connection intermittently (round-robin?) (assume that one is the max and browser will not create second persistent connection) – Sam YC Feb 10 '14 at 04:51