OT: limit number of connections from browser to my server?

Grant Edwards grant.b.edwards at gmail.com
Wed May 18 16:45:19 EDT 2016


On 2016-05-16, Grant Edwards <grant.b.edwards at gmail.com> wrote:

> Is there any way to limit the number of connections a browser uses to
> download a web page?

[Long-winded tail of woe...]

> So now I'm going to set up a simple Python HTTP server to try some
> other approaches:
>
>   1) Only allow the listening socket to accept 1 connection at a time.

That doesn't work.  If you refuse connections, at least one browser
(Chrome) fails some of the fetches and you end up sans css, js, png,
whatever.

>   2) Accept the TCP connection, but don't allow the SSL handshaking to
>      start on the "extra" connections.

That seems to work for Chrome (which seems to be the worst of the
lot).

If on the 2nd, 3rd, 4th, 5th connections you accept the TCP connection
and then stall before doing the SSL hadshake, Chrome stays happy _and_
will shift all fetches to the one connection who's handshake has
finished.  You probably can't depend on this behavior, but OTOH it
can't hurt.  However, since the web server is single-threaded, doing
this in practice ends up be rather complicated.

>   3) ???

I did find a bug in the glue between the SSL stack and the web server
that was causing (under certain conditions) an ssl-read operation to
block when it shouldn't.  Fixing that brought my cold page load time
down from 15 to 7-9 seconds.

The most promising approach is probably to minimize the number of
files by doing server-side includes for css, js, and image data.  If I
also add support for chunked transport, that should make a big
difference.  There are currently certain cases where the reply size
isn't known, so the connection can't be left open and re-used.  Each
time a connection has to be closed by ther server to indicate
endof-response, it's a big performance hit.  If the browser supported
chunked transport, it should allow all connections to be left open and
reused.  That would then makes a huge difference on subsequent page
load times as people work with the thing...

-- 
Grant Edwards               grant.b.edwards        Yow! I'm having BEAUTIFUL
                                  at               THOUGHTS about the INSIPID
                              gmail.com            WIVES of smug and wealthy
                                                   CORPORATE LAWYERS ...




More information about the Python-list mailing list