Re: [hybi] Multiplexing in WebSocket (Was: HyBi Design Space)

Graham Klyne <gk-ietf-hybi@ninebynine.org> Tue, 13 October 2009 18:03 UTC

Return-Path: <gk-ietf-hybi@ninebynine.org>
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 1D15E3A68ED for <hybi@core3.amsl.com>; Tue, 13 Oct 2009 11:03:46 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.936
X-Spam-Level:
X-Spam-Status: No, score=-2.936 tagged_above=-999 required=5 tests=[AWL=0.505, BAYES_05=-1.11, DATE_IN_PAST_06_12=1.069, J_CHICKENPOX_31=0.6, RCVD_IN_DNSWL_MED=-4]
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 WYsKn94oa1Le for <hybi@core3.amsl.com>; Tue, 13 Oct 2009 11:03:44 -0700 (PDT)
Received: from relay9.mail.ox.ac.uk (relay9.mail.ox.ac.uk [163.1.2.169]) by core3.amsl.com (Postfix) with ESMTP id 5DD9428C0E1 for <hybi@ietf.org>; Tue, 13 Oct 2009 11:03:44 -0700 (PDT)
Received: from smtp2.mail.ox.ac.uk ([163.1.2.205]) by relay9.mail.ox.ac.uk with esmtp (Exim 4.69) (envelope-from <gk-ietf-hybi@ninebynine.org>) id 1Mxlip-000478-TN; Tue, 13 Oct 2009 19:03:43 +0100
Received: from gklyne.plus.com ([80.229.154.156] helo=Eskarina.local) by smtp2.mail.ox.ac.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from <gk-ietf-hybi@ninebynine.org>) id 1Mxlio-0004SW-8i; Tue, 13 Oct 2009 19:03:43 +0100
Message-ID: <4AD4482B.3030705@ninebynine.org>
Date: Tue, 13 Oct 2009 10:28:11 +0100
From: Graham Klyne <gk-ietf-hybi@ninebynine.org>
User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812)
MIME-Version: 1.0
To: Greg Wilkins <gregw@webtide.com>
References: <4ACE50A2.5070404@ericsson.com> <3a880e2c0910081600v3607665dp193f6df499706810@mail.gmail.com> <4ACF4055.6080302@ericsson.com> <Pine.LNX.4.62.0910092116010.21884@hixie.dreamhostps.com> <4AD2E353.8070609@webtide.com> <4AD2F43D.6030202@ninebynine.org> <4AD39A64.4080405@webtide.com>
In-Reply-To: <4AD39A64.4080405@webtide.com>
Content-Type: text/plain; charset="ISO-8859-1"; format="flowed"
Content-Transfer-Encoding: 7bit
X-Oxford-Username: zool0635
Cc: "hybi@ietf.org" <hybi@ietf.org>
Subject: Re: [hybi] Multiplexing in WebSocket (Was: HyBi Design Space)
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: Tue, 13 Oct 2009 18:03:46 -0000

Greg Wilkins wrote:
> Graham Klyne wrote:
>> To add just one voice among many...
>>
>> (1) in the use-cases that I've considered for pushing messages/requests
>> to a browser, multiplexing is not a requirement.  Other's mileage may,
>> of course, vary.
> 
> Graham, it would be great if you could briefly describe
> your use-cases.

Primarily event delivery for real-time control and monitoring.  A few more notes 
are here: http://code.google.com/p/webbrick-events/wiki/EventModel.

Also, as noted there, providing notification that data has changed so that web 
pages can refresh themselves.

These applications are essentially channel-free, being more 
datagram/message/event oriented than session oriented, using some kind of global 
identifier space (e.g. URIs) for disambiguation where needed.

I'm also in conversation with the Wookie Widgets team 
(http://getwookie.org/Welcome.html) for another project I'm working on 
(http://code.google.com/p/shuffl/).

> Are you sure that they will never be mashed up into a webapp made
> of many parts that originally were not designed to work together?

No, I'm not, but I'm also prepared to consider using multiple TCP connections in 
such circumstances.  Typically, I've seen requirements to put up to about 5 
different semi-independent widgets on a page.

I fully accept that your mileage may vary here.

Also, I seem to recall there was some IETF work on congestion control that could 
  reduce some of the problems with running multiple TCP channels ...

[Googling...]
http://tools.ietf.org/html/rfc2914
http://tools.ietf.org/html/rfc2481
http://tools.ietf.org/html/rfc4336
http://tools.ietf.org/html/rfc3124

I think the last one is the one I recall.

> Are you sure that they would never run behind a transparent proxy
> that might aggregate multiple connections into a single connection?

No I'm not, but any transparent proxy that does that must surely ensure that 
multiple connections still appear to the application as independent connections, 
or it's fundamentally broken.  I think that such multiple connection tunneling 
might be the right way to go.  I could imagine server-to-server BEEP being used 
to tunnel multiple WebSocket sessions over a single connection - and here, the 
complexity of BEEP might be justified.

>> (2) Looking at a multiplexing protocol such as BEEP, multiplexing adds a
>> *lot* of complexity to the protocol specification and implementation.  I
>> would say that the case for multiplexing in the base protocol needs to
>> be made to justify that added complexity.
> 
> I totally agree that the multiplexing of BEEP is too complex for
> the level of protocol that we are considering.
> 
> But multiplexing can be much much simpler.  At it simplest,
> it just needs a channel id in each frame and the channel creation
> can be automatic.   In the BWTP protocol proposal, I've added
> a little bit of channel creation exchange, so as to well match
> the explicit life cycle events of the websocket API.

I guess that I'm not convinced that you can make multiplexing much simpler than 
BEEP and not end up being broken.  When I reviewed BEEP a few years back, I 
thought about trying to avoid the complexities of per-channel flow control, but 
in the end I couldn't see any way of doing that without running the risk that 
one channel could starve all the others.  But with per-channel flow control 
comes the need for some quite complex buffering arrangements.

>> (3) It seems to me that, if needed, a multiplexing layer could be
>> specified and standardized over a non-multiplexing substrate.
> 
> Normally I do believe layering protocols like you describe would be
> a good approach. But...
> 
> The difficulty is that with websocket protocol, it has a hard binding
> to the application websocket API.  There is no scope provided to inject
> another layer.   The API has explicit  open/close events (which I think
> should be mapped to channels), but that are currently mapped to connections.
> Thus applications and/or frameworks will be doing explicit connection
> management.

Hmmm... in principle, I understand that HTTP can be run over any full-duplex 
connection.  I see nothing in WebSockets that prevents similar behaviour.

> This is analogous to the advent of XHR in the browser. Every Ajax
> books then started with a chapter about how to write your own Ajax
> code directly using XHR.  But XHR is a too low level API for
> applications and it has taken many years to abstract the average
> ajax developer away from direct XHR access.  So now we have
> frameworks such as dojo, jquery, yahoo, ext etc that provide an
> abstraction on top of XHR.

While I can agree that the XHR interface is too low-level, and that there are 
better abstractions, and I could agree that the API makes it harder to multiplex 
on a connection, I don;t see anything in the API that actually makes such 
multiplexing impossible.

Also, I haven't really studied a WebSocket API as such - I have looked at a 
protocol spec.  I might agree that an API design should not make it hard to 
multiplex, but that's a different question to what I understood to be under 
discussion here.

> Probably these frameworks will be able to provide good abstractions
> on top of websocket API, and this may well include multiplexing
> support.   But even if the frameworks implemented to same wire
> protocol for multiplexing, they would not be able to:
> 
>   + share connections between frameworks
>   + share connections with code written directly to the websocket API.
>   + share connections with other iframes, tabs and/or windows.
>   + implement a strong origin policy for security
> 
> 
> I believe that these desirable things can only be achieved if
> it is the browser rather than the application that implements
> the multi-plexing.
> 
> The fundamental problem with websocket API is that is both
> a connection API (open/close) and a messaging API (send/onMessage).
> The API needs to be abstracted away from any hard relationship
> to TCP/IP connections.   This can be done with a simple rename
> of s/connection/channel/.     Applications can then manage channels
> and the browser/server can manage mapping those channels to
> connections - perhaps with multiplexing or perhaps without.

These are reasonable points, but see above my comments of API vs protocols.

I can also see that there may be aspects of the protocol I've not noticed that 
make such abstraction harder, and which can be fixed relatively cheaply.  (I'm 
thinking of examples like the original FTP protocol being hard to run through 
NAT - not that I claim that's a good example of desirability).

#g