Re: [hybi] Background info: Properties of sendfile()

Greg Wilkins <gregw@webtide.com> Fri, 06 August 2010 01:41 UTC

Return-Path: <gregw@webtide.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 F00BE3A6958 for <hybi@core3.amsl.com>; Thu, 5 Aug 2010 18:41:22 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.749
X-Spam-Level:
X-Spam-Status: No, score=-1.749 tagged_above=-999 required=5 tests=[AWL=0.228, 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 eo2qH1i8Yjtl for <hybi@core3.amsl.com>; Thu, 5 Aug 2010 18:41:21 -0700 (PDT)
Received: from mail-fx0-f44.google.com (mail-fx0-f44.google.com [209.85.161.44]) by core3.amsl.com (Postfix) with ESMTP id 2486F3A6934 for <hybi@ietf.org>; Thu, 5 Aug 2010 18:41:20 -0700 (PDT)
Received: by fxm16 with SMTP id 16so2953961fxm.31 for <hybi@ietf.org>; Thu, 05 Aug 2010 18:41:51 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.223.119.67 with SMTP id y3mr11836783faq.45.1281058911407; Thu, 05 Aug 2010 18:41:51 -0700 (PDT)
Received: by 10.223.57.12 with HTTP; Thu, 5 Aug 2010 18:41:51 -0700 (PDT)
In-Reply-To: <20100806012845.GI27827@shareable.org>
References: <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> <4C5B2029.90403@gmx.de> <AANLkTim1WeCRfcPxXUNQcVhb4+t_TtDQDv2bXaxOQ=bk@mail.gmail.com> <01098AD0-FBF4-4A61-B565-947C95722BAA@apple.com> <AANLkTi=qQSND5BvUP5+P=wJ7E8SG6NncGZH8U8+VYwZ0@mail.gmail.com> <20100806004907.GF27827@shareable.org> <C0FC87B7-C51C-4B36-BC16-DBDB0B00A20F@gbiv.com> <20100806012845.GI27827@shareable.org>
Date: Fri, 06 Aug 2010 11:41:51 +1000
Message-ID: <AANLkTi=GQOmgtg23XkGSc8NG5RDJP5wVY83P1VcG2AJZ@mail.gmail.com>
From: Greg Wilkins <gregw@webtide.com>
To: Jamie Lokier <jamie@shareable.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Cc: "Roy T. Fielding" <fielding@gbiv.com>, "hybi@ietf.org" <hybi@ietf.org>
Subject: Re: [hybi] Background info: Properties of sendfile()
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 01:41:23 -0000

On 6 August 2010 11:28, Jamie Lokier <jamie@shareable.org> wrote:
> Roy T. Fielding wrote:
>> On Aug 5, 2010, at 5:49 PM, Jamie Lokier wrote:
>>
>> > It's time to explain sendfile() better.
>> >
>> > 0. Nearly all OSes used for web serving have something called
>> >   sendfile() or under a different name.  It has become a standard
>> >   method used in high performance static servers, and is beginning to
>> >   be used in dynamic servers that do smart caching.  It is given an
>> >   open file handle and range, and writes content of that file to a
>> >   TCP socket as efficiently as possible.  Some OSes allow contents of
>> >   process memory to be sent as well.
>>
>> Unfortunately, you should also be aware that nearly all OSes have
>> severe kernel bugs in their implementations of sendfile and seem
>> to be getting progressively worse over time, to the point where
>> Apache httpd needs to disable it by default.  I don't know why.
>
> Thanks.  Ugh.  (I would like to know more, if you can point me at the details.)

For jetty using java's file mapped buffers, we've encountered 2 key
problems that cause us to turn it off.
Firstly because the file is mapped to address space, even if it is not
actually loaded into user space, there was a problem with leaking
address space. Once mapped the address range was never recovered, even
if the buffer was discarded. It was possible (on 32 bit machines) to
consume all the available address space by repeatedly creating and
sending large files.  I'm not sure if this was an OS flaw or just the
way the JVMs expose the feature as a memory mapped buffer.
We also have issues with the windows implementation which causes the
file system to lock the file if it is mapped.  This can prevent hot
redeploys and efficient development cycles.

But even if the send file semantic is not always available, it is a
big gain when it is available.  So having support for large frames is
good.

> I.e. it just means "don't mandate that chunks must be small".
> It's not asking much.

So is 16 exebytes enough for you (see Ian's email).
Not sure how I'm going to write a unit test for that one:)



cheers