Re: [hybi] frame length encoding

"Shelby Moore" <shelby@coolpage.com> Sat, 21 August 2010 17:31 UTC

Return-Path: <shelby@coolpage.com>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id 5B6D53A695B for <hybi@core3.amsl.com>; Sat, 21 Aug 2010 10:31:22 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.065
X-Spam-Level:
X-Spam-Status: No, score=-2.065 tagged_above=-999 required=5 tests=[AWL=0.534, BAYES_00=-2.599]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vXtKF3nACBN9 for <hybi@core3.amsl.com>; Sat, 21 Aug 2010 10:31:20 -0700 (PDT)
Received: from www5.webmail.pair.com (www5.webmail.pair.com [66.39.3.83]) by core3.amsl.com (Postfix) with SMTP id 032513A6954 for <hybi@ietf.org>; Sat, 21 Aug 2010 10:31:19 -0700 (PDT)
Received: (qmail 39870 invoked by uid 65534); 21 Aug 2010 17:31:52 -0000
Received: from 121.97.54.174 ([121.97.54.174]) (SquirrelMail authenticated user shelby@coolpage.com) by sm.webmail.pair.com with HTTP; Sat, 21 Aug 2010 13:31:52 -0400
Message-ID: <8dea23aa73d8065b3f286852af659362.squirrel@sm.webmail.pair.com>
In-Reply-To: <AANLkTinkYMN8LyU7432v2PZjrQ0Z7cN7mcwwzYwCwhON@mail.gmail.com>
References: <AANLkTimKbmcpgx8k0uXUWvCO=8w9pPrtV=3y4qh6363k@mail.gmail.com> <20100820192927.GA32620@1wt.eu> <4C6EEA55.2050205@hs-weingarten.de> <AANLkTinHqxUOZaVANFpC52t8FfgNw2L5_A-s9Az3Fm7p@mail.gmail.com> <9038007a07cb2e7f2659663b8bc6af82.squirrel@sm.webmail.pair.com> <8586ffdbc1c035a949df3965da5f489a.squirrel@sm.webmail.pair.com> <AANLkTinkYMN8LyU7432v2PZjrQ0Z7cN7mcwwzYwCwhON@mail.gmail.com>
Date: Sat, 21 Aug 2010 13:31:52 -0400
From: Shelby Moore <shelby@coolpage.com>
To: John Tamplin <jat@google.com>
User-Agent: SquirrelMail/1.4.20
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
Cc: Hybi <hybi@ietf.org>
Subject: Re: [hybi] frame length encoding
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
Reply-To: shelby@coolpage.com
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 21 Aug 2010 17:31:23 -0000

> On Sat, Aug 21, 2010 at 11:14 AM, Shelby Moore <shelby@coolpage.com>
> wrote:
>
>> Correction:
>>
>> long long len = readByte();
>> if (len >= 128)
>>     len = ((len & 0x7f) << 8) + readByte();
>> else if (len == 127)
>>    len = readLongLong();
>>
>
> Ok, so you are suggesting using RSV2 to differentiate 7/63-bit from 15-bit
> lengths, and then within the 7/63-bit option using a value of 127 to do
> so,
> right?

Yes.

I assume that reserved bit is in the size field because all the other
8-bit groups of bit fields were allocated? That wastes 7-bits. We could
recover the 7-bits and keep the reserved bit, if we are willing to have a
header which is not byte aligned (1 extra bit in length), but the code
gets more convoluted:

long long read = readUnsignedshort();
long long len = read >> 7;
read &= 0x7f;
if (len >= 128)
    len = ((len & 0x7f) << 8) + (read << 8) + ((read = readByte()) >> 7);
else if (len == 127)
   len = (read << 8) + ((read = readLongLong()) >> 7);
read &= 0x7f;

> I still dislike using up one of the reserved bits, as it reduced our
> expansion options.


Why did you decide to put a reserved bit in middle of a size field if that
bit is not already allocated to specific use?

Apologies I have not yet read the entire frame header design discussion.


>  Also, as posted previously, I think once compression
> is
> supported, an overwhelming majority of real-world WebSocket messages will
> fit in ~126 bytes.  That is why I am mostly indifferent between option 1
> and
> 2 -- I don't think the 2-byte length value will get used very often (I
> expect mostly small frames with some very large frames where an entire
> file
> is sent in one message), but the cost of adding it over option 1 is
> relatively small (packets of exactly 126 bytes now take 2 bytes longer,
> everything else is the same).


And just in case there is ever a use case for the frames larger than 126
but less than 65535 in size.

Agreed it is only the 126 frame length that has any penalty.

And if we don't need the extra reserved bit (or if we can use a 1 bit
longer header), then there is no penalty at all.

But I guess the logic is that it is better throw away 7 bits for the 126
to 65535 frame byte sizes, than to add 1 bit to frame smaller than 126
bytes in size?

7 bits / (126 x 8 bits) = 0.7%

The break even point is 126 / 7 = 18 byte frame sizes.  We would need to
know the distribution of frame sizes we expect to make a decision of what
is more cost effective.  But it is minor in either case, and the bit
twiddling for non-byte aligned headers has some cost mostly in terms of
software error.


> I do prefer your proposal over Option #3, which also uses one reserved
> bit,

Agreed, gets rid of the error case.

> but otherwise I still prefer either #1 or #2 because I think removing 1/3
> of
> our expansion capability is excessive for what is gained.

Okay but we could get it back if we want to have non-byte aligned headers.


> The reason I feel strongly about keeping reserved bits available for
> expansion, is that we have not yet agreed on how extensions should work.
> If
> we decide to go the nested opcode approach (an extension opcode uses the
> first part of the payload data for its extension data, then the next
> opcode
> etc, until you get to a "data" opcode that uses what is left), then I
> think
> we are going to need to assign both RSV1 bits to the opcode to be able
> to accommodate extensions there (remember that we don't want to have to
> change the base framing protocol at all and this protocol will hopefully
> be
> used for a long time).  If we decide to have per-frame compression
> (certainly still up for debate), then we will likely need a single bit per
> frame to indicate compression efficiently (there are certainly other ways
> to
> do it as well).  If we decide to have separate extension metadata, we will
> need a bit to indicate an extension length and extension data is present.
>  And those are just the extensions we have been talking about the past few
> months -- who knows what things we may come up with in the future that
> might
> be more efficiently implemented if we assign one of the reserved bits
> rather
> than an extension data block or an opcode?
>
> --
> John A. Tamplin
> Software Engineer (GWT), Google
>