Re: [hybi] hum #3: Message

Pieter Hintjens <ph@imatix.com> Fri, 06 August 2010 09:15 UTC

Return-Path: <pieterh@gmail.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 A65E03A6829 for <hybi@core3.amsl.com>; Fri, 6 Aug 2010 02:15:14 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.619
X-Spam-Level:
X-Spam-Status: No, score=-1.619 tagged_above=-999 required=5 tests=[AWL=0.358, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622]
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 JDmKZLLme7Cc for <hybi@core3.amsl.com>; Fri, 6 Aug 2010 02:15:13 -0700 (PDT)
Received: from mail-ww0-f44.google.com (mail-ww0-f44.google.com [74.125.82.44]) by core3.amsl.com (Postfix) with ESMTP id 903493A65A5 for <hybi@ietf.org>; Fri, 6 Aug 2010 02:15:13 -0700 (PDT)
Received: by wwj40 with SMTP id 40so864901wwj.13 for <hybi@ietf.org>; Fri, 06 Aug 2010 02:15:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=hQGgN6v67zE3JYaymVLQDxFJtuHyLO3upWK2ql4SUP8=; b=bLsuQ0f8tqGaBc51IDnEBis53XWpIgMjV1jfZ4Jzcbx7brPs6dz5LLEnlUUY8hQ031 lF1v1bzi8FWAK/2brXJ9n1PTgRoLG5eKpw87WJMbHVEe4Tvx+02qkg7QWPwvXBQuJR1J CGVFuTlPqjIi97X8gIHKoFlIaKOsxmFg0kSqQ=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=H4kRCeeLpK8Ulp99kfij4Ukv7MNjTr/BWvunu7WLil7plTGbHcKuqvBa2RJDlpU9Tl o0eJO1fHYybwYSdx9sTCAJZXCs+umlJeeBtHfr9ZRX18LxexC1RvQfflKu/DOXIbraun ilGkPQ5XHAjgh78OvgYij4HGN4WGnmFU8nLyw=
Received: by 10.216.17.130 with SMTP id j2mr637314wej.47.1281086144210; Fri, 06 Aug 2010 02:15:44 -0700 (PDT)
MIME-Version: 1.0
Sender: pieterh@gmail.com
Received: by 10.216.80.15 with HTTP; Fri, 6 Aug 2010 02:15:24 -0700 (PDT)
In-Reply-To: <F8E2F702-9F74-4316-B3B2-D5A731409ABF@apple.com>
References: <4C5AE93D.4040803@ericsson.com> <Pine.LNX.4.64.1008051758290.5947@ps20323.dreamhostps.com> <AANLkTik0kbh14s2JZARY2MFh0iNGV7H+B4Px4yG+wX44@mail.gmail.com> <71BCE4BF-D3F6-4F94-BE76-306BDF6A2E67@apple.com> <Pine.LNX.4.64.1008051930160.5947@ps20323.dreamhostps.com> <4C5B1695.6070704@gmx.de> <F8E2F702-9F74-4316-B3B2-D5A731409ABF@apple.com>
From: Pieter Hintjens <ph@imatix.com>
Date: Fri, 06 Aug 2010 11:15:24 +0200
X-Google-Sender-Auth: tYHBBftOpEew5iseJpOelN9iTa8
Message-ID: <AANLkTin=gO9D8K5NVhqCRKki-jrDmTYqF-gBjp9X41GN@mail.gmail.com>
To: Maciej Stachowiak <mjs@apple.com>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
Cc: "hybi@ietf.org" <hybi@ietf.org>
Subject: Re: [hybi] hum #3: Message
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
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: Fri, 06 Aug 2010 09:15:15 -0000

On Thu, Aug 5, 2010 at 10:21 PM, Maciej Stachowiak <mjs@apple.com> wrote:

> Sending a file from disk to the network without processing it in any way is more efficient than cutting it into slices and interleaving with headers. The IP layer is already going to cut it into slices, in a way that almost certainly won't line up with WebSocket-level fragment boundaries.
>
> It's also more efficient for the receiver if they know the length up front. That way they can determine whether to allocate a large enough buffer, or just start spooling to persistent storage immediately.

Agree with both these points.  If a sender does fragment a large
message, they ALSO need to specify the full size up front, for the
same reasons we specify the frame size up front.  You want to avoid
sentinel-based reads.

Content framing sounds simple but is actually one of those things that
gets complex to implement.

There is a very simple solution that addresses both efficiency for
small messages, and easy of framing for very large messages.

Rather than a fixed two-byte length, use a 1-byte length which escapes
into an 8-byte length for frames longer than 254 bytes.  Small
messages, which are the most important for high latency and high
frequency scenarios, are optimally encoded.  Long messages are most
trivially encoded.

If you really want a 4-byte header, use a two-byte length that escapes
into an 8-byte length.

I'd strongly advise, based on experience, to avoid frame fragmentation
as a way of encoding long frames.  Multiple frames per message IS
valuable but for other reasons (multipart).

-Pieter