Re: delta encoding and state management

Willy Tarreau <w@1wt.eu> Wed, 23 January 2013 00:02 UTC

Return-Path: <ietf-http-wg-request@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 258FB21F8B02 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Tue, 22 Jan 2013 16:02:05 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -10.079
X-Spam-Level:
X-Spam-Status: No, score=-10.079 tagged_above=-999 required=5 tests=[AWL=0.520, BAYES_00=-2.599, RCVD_IN_DNSWL_HI=-8]
Received: from mail.ietf.org ([64.170.98.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id psOhH8YOHHBm for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Tue, 22 Jan 2013 16:02:04 -0800 (PST)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) by ietfa.amsl.com (Postfix) with ESMTP id 29F9321F880F for <httpbisa-archive-bis2Juki@lists.ietf.org>; Tue, 22 Jan 2013 16:02:03 -0800 (PST)
Received: from lists by frink.w3.org with local (Exim 4.72) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1Txnlv-00014N-NG for ietf-http-wg-dist@listhub.w3.org; Wed, 23 Jan 2013 00:00:55 +0000
Resent-Date: Wed, 23 Jan 2013 00:00:55 +0000
Resent-Message-Id: <E1Txnlv-00014N-NG@frink.w3.org>
Received: from maggie.w3.org ([128.30.52.39]) by frink.w3.org with esmtp (Exim 4.72) (envelope-from <w@1wt.eu>) id 1Txnlq-000138-PR for ietf-http-wg@listhub.w3.org; Wed, 23 Jan 2013 00:00:50 +0000
Received: from 1wt.eu ([62.212.114.60]) by maggie.w3.org with esmtp (Exim 4.72) (envelope-from <w@1wt.eu>) id 1Txnlp-0004B9-Mm for ietf-http-wg@w3.org; Wed, 23 Jan 2013 00:00:50 +0000
Received: (from willy@localhost) by mail.home.local (8.14.4/8.14.4/Submit) id r0N00IrL032467; Wed, 23 Jan 2013 01:00:18 +0100
Date: Wed, 23 Jan 2013 01:00:18 +0100
From: Willy Tarreau <w@1wt.eu>
To: "William Chan (?????????)" <willchan@chromium.org>
Cc: James M Snell <jasnell@gmail.com>, Nico Williams <nico@cryptonector.com>, Roberto Peon <grmocg@gmail.com>, "ietf-http-wg@w3.org" <ietf-http-wg@w3.org>
Message-ID: <20130123000018.GR30692@1wt.eu>
References: <CAK3OfOj3ZgOZnzcQCifhb9f2One7vBUNGv7yhidkZqRzaeZYvQ@mail.gmail.com> <CAP+FsNfswUN-CK6heRGqEnSJatHGo3q2mZZLTrPnjapCZz2sTg@mail.gmail.com> <CABP7RbfDZcRH-0_AaN9iYjPN-v6QjU6_Xdy5o1BHYnDFWHtuAg@mail.gmail.com> <CAK3OfOh0xqZsPYcb0uRLnebKWTKO7ARkJ4joFZoqjiBSTmwBTA@mail.gmail.com> <CABP7Rbeb6MOYmYPhhsKFFtQwE0JxuPyShXY0zpkA5YX2JPSY_w@mail.gmail.com> <CAA4WUYhg2qt_z_TrOAH0ax6mUpYPNeG4x740CgQi5Voq=50K_Q@mail.gmail.com> <20130122212748.GJ30692@1wt.eu> <CAA4WUYj51jRFosut2RsdE46SqoMDqa_r5EB7g4pj5eC2i73j7Q@mail.gmail.com> <20130122224646.GO30692@1wt.eu> <CAA4WUYjuCGyJjA2nN_-oh8TunrA7owWFQRhLg-ps+fkp9T47Ew@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <CAA4WUYjuCGyJjA2nN_-oh8TunrA7owWFQRhLg-ps+fkp9T47Ew@mail.gmail.com>
User-Agent: Mutt/1.4.2.3i
Received-SPF: pass client-ip=62.212.114.60; envelope-from=w@1wt.eu; helo=1wt.eu
X-W3C-Hub-Spam-Status: No, score=-3.0
X-W3C-Hub-Spam-Report: AWL=-3.009, RP_MATCHES_RCVD=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001
X-W3C-Scan-Sig: maggie.w3.org 1Txnlp-0004B9-Mm 3abeabcddfc2f114c5ce59e5472cbd5e
X-Original-To: ietf-http-wg@w3.org
Subject: Re: delta encoding and state management
Archived-At: <http://www.w3.org/mid/20130123000018.GR30692@1wt.eu>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/16123
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <http://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

On Tue, Jan 22, 2013 at 03:08:08PM -0800, William Chan (?????????) wrote:
> >> How long do you delay
> >> the resource request in order to consolidate requests into a load
> >> group? The same thing is even more true for response headers.
> >
> > I never want to delay anything, delays only do bad things when we
> > try to reduce latency.
> 
> One of us has the wrong mental model for how the proposal would work.
> Let's figure this out.
> 
> Let's say the browser requests foo.html. It receives a response packet
> for foo.html, referencing 1.js. 5ms later, it receives packet 2 for
> foo.html which references 2.js. 5ms it receives packet 3 for foo.html
> which references 3.js. And so on. You say no delays. So does this mean
> each "group" only includes one object each time?

Ah OK I didn't understand. My assumption was that browsers do have a list
of objects to be fetched, but with what you're explaining, it might not
always be true. Anyway the principle I proposed suggested that all subsequent
requests remain in the same group until a new group is emitted, so that
should cover the need for new objects that are discovered one at a time.
However, I do think (but may be wrong) that objects are not often scheduled
to go on the wire one at a time, but that when many objects appear in the
contents, many of them are seen together.

> And now let's ignore the 5ms delays. Consider how WebKit works. Let's
> say WebKit has all of foo.html. It starts parsing it. It encounters
> 1.js. It immediately sends the resource request to the network stack.
> It hasn't parsed the full document yet, so it doesn't know if it'll
> encounter any more resources. Each time it encounters a resource while
> parsing the document, it will send it to the network stack (in
> Chromium and latest versions of Safari, this is a separate process).

I must say I'm a bit shocked by this behaviour which is very inefficient
from a TCP point of view. This means you have two possibilities for sending
your requests then :
  - either you keep Nagle enabled and your requests wait in the kernel's stack
    for some time (typically 40 ms) before leaving, even if the request is
    the last one ;

  - or you disable Nagle to force them to leave immediately, but then each
    request leaves with a TCP push flag, and then your TCP stack will not
    send anything else over the same socket for a full RTT (until its pending
    data are ACKed), which is worse.

This is why we generally try to fill packets over the wire as much as
possible. An alternative consists in opening many connections but this
is not efficient either then (RTTs, upstream packets).

So in practice I suspect that you already send requests with Nagle enabled
and disable it when you reach the end of the page, so that whatever can leave
is delayed at most 40ms and never more than the time to parse the whole page.
If this is the case, then you already have your requests delayed by as much
as 40ms and sent as groups.

> What is the network stack to do if, as you say, it should never delay
> anything? If I understand correctly, each "group" would always only
> include one object then.

I did not understand you meant delay between objects while parsing, I
thought you meant delay between groups.

Here you're limited by TCP. If you push too fast, you have to wait one RTT
between requests. If you ask the kernel to disable quick ACK or if you keep
NAGLE enabled (using TCP_CORK, MSG_MORE, etc...), your requests will
automatically leave between 40 and 200ms even if incomplete (far too much).

However, considering that only incomplete packets will remain pending
for the time it takes to parse the page and will leave anyway if it takes
longer than that, I think it remains optimal to feed the kernel's buffers
and let the first of the kernel or the HTML parser decide to send incomplete
segments. Otherwise you'd delay subsequent requests by an RTT in the TCP
stack.

> > In the example I proposed, the recipient receives the full headers
> > block, then from that point, all requests reuse the same headers
> > and can be processed immediately (just like pipelining in fact).
> >
> > Concerning response headers, I'd say that you emit a first response
> > group with the headers from the first response, followed by the
> > response. When another response comes in, you have two possibilities,
> > either it shares the same headers and you can add a response to the
> > existing group, or it does not and you open a new group.
> 
> Wait, is this the critical misunderstanding? Are you maintaining state
> across requests and responses? Isn't this a minor modification on the
> "simple" compressor? I was assuming you were trying to be stateless.

I'm having a hard time following you, I'm sorry. What state across requests
and responses do you mean ? The only "state" I'm talking about is the list
of common headers between the current message and the previous one in fact.
This is true both for requests and responses.

Regards,
Willy