Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108702

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

From Grant Edwards <grant.b.edwards@gmail.com>
Newsgroups comp.lang.python
Subject Re: OT: limit number of connections from browser to my server?
Date 2016-05-16 22:09 +0000
Message-ID <mailman.37.1463436577.19823.python-list@python.org> (permalink)
References <nhcr5g$o1k$1@ger.gmane.org> <mailman.17.1463414817.19823.python-list@python.org> <5739ff37$0$1605$c3e8da3$5496439d@news.astraweb.com> <nhdgem$u2u$1@ger.gmane.org>

Show all headers | View raw


On 2016-05-16, Steven D'Aprano <steve@pearwood.info> wrote:
> On Tue, 17 May 2016 02:06 am, Grant Edwards wrote:
>
>> This is not Python specific, though I'm turning to Python to do some
>> experimentation and to try to prototype a solution.
>> 
>> Is there any way to limit the number of connections a browser uses to
>> download a web page?
>
> Well, you control the server. It's your own server, right? Can you not tell
> the server to limit how many connections it accepts from any one client?

I tried two approaches on Linux using a Python server prototype that
has some code I wrote that accepts connections and then calls
SimpleHTTPRequestHandler.  For starters I'm sticking with HTTP (no
SSL) and just stuck a 2-second (delay to simulate SSL startup time)
between the accept() returning and the call to the request handler .

 1) Refuse to accept more than one connection at a time by closing the
    listening socket while there is an active connection.  On both
    Firefox and Chrome, this gets you the initial HTML page and
    perhaps one addition file (css, js, png, whatever).  The files
    that the browser normally requests using the addition 4-5 requests
    simply fail (broken img, missing css and js files).  The Chrome
    network monitor thingy shows those as "failed".  In my test case,
    only allowing a single connection resulted in 7 failed files out
    of the 9 which are loaded for the page.

 2) Limit the listen() backlog to 0.  On Linux, a 0 backlog doesn't
    prevent the stack from sending back a SYN/ACK in response to a
    SYN.  It just prevents the connection from ACKing anything else
    that's sent by the client.  This makes the client think the
    connection is open. In my tests, the browser then sits there
    waiting for a response on what it _thinks_ is an open TCP
    connection.  It eventually times out and fails.

It looks to me like the browsers decide how many connections to use
(in my test case it's usually around 5), assigns individual files to
each connection, and then presses "go".  If any connection fails,
stalls, or falls over, the files assigned to that connection are
failed rather than fetched from an extant working connection.

Next I'll try adding the SSL layer -- perhaps stalling the connection
after the accept() and before the SSL handshake will have a different
affect on the browser that stalling a plaintext TCP connection before
responding to the request.

-- 
Grant Edwards               grant.b.edwards        Yow! PARDON me, am I
                                  at               speaking ENGLISH?
                              gmail.com            

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

OT: limit number of connections from browser to my server? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-16 16:06 +0000
  Re: OT: limit number of connections from browser to my server? Steven D'Aprano <steve@pearwood.info> - 2016-05-17 03:11 +1000
    Re: OT: limit number of connections from browser to my server? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-16 19:28 +0000
    Re: OT: limit number of connections from browser to my server? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-16 22:09 +0000
      Re: OT: limit number of connections from browser to my server? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-05-17 18:06 +1200
        Re: OT: limit number of connections from browser to my server? Marko Rauhamaa <marko@pacujo.net> - 2016-05-17 09:23 +0300
          Re: OT: limit number of connections from browser to my server? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-17 14:23 +0000
        Re: OT: limit number of connections from browser to my server? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-17 14:22 +0000

csiph-web