From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id A674BBBAF for ; Wed, 27 Oct 2010 13:18:38 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAAqnx0zVuiYS/2dsb2JhbAChWHG8QA2FOwQ X-IronPort-AV: E=Sophos;i="4.58,246,1286143200"; d="scan'208";a="85577590" Received: from solaria.dimino.org ([213.186.38.18]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Oct 2010 13:18:38 +0200 Received: from aurora (localhost.localdomain [127.0.0.1]) by solaria.dimino.org (Postfix) with ESMTP id A31D580048; Wed, 27 Oct 2010 13:18:37 +0200 (CEST) Received: by aurora (Postfix, from userid 1000) id 08C98401A8; Wed, 27 Oct 2010 13:18:35 +0200 (CEST) Date: Wed, 27 Oct 2010 13:18:35 +0200 From: =?iso-8859-1?Q?J=E9r=E9mie?= Dimino To: Goswin von Brederlow Cc: Yaron Minsky , caml-list@inria.fr Subject: Re: [Caml-list] Asynchronous IO programming in OCaml Message-ID: <20101027111835.GA5664@gaia> References: <20101024225037.GA8999@aurora> <87y69mk6jm.fsf@frosties.localdomain> <20101025111022.GA32282@aurora> <20101025143317.GB32282@aurora> <20101025172633.GC32282@aurora> <877hh4dlog.fsf@frosties.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <877hh4dlog.fsf@frosties.localdomain> User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam: no; 0.00; ocaml:01 0200,:01 prefetching:01 runtime:01 threads:01 threads:01 wrote:01 caml-list:01 kernel:02 asynchronous:03 programming:03 let:03 overhead:04 overhead:04 depends:04 On Wed, Oct 27, 2010 at 11:33:51AM +0200, Goswin von Brederlow wrote: > You aren't doing any multithreading. You are creating a thread and > waiting for the thread to finish its read before strating a second. > There are never ever 2 reads running in parallel. So all you do is add > thread creation and destruction for every read to your first example. Yes, i know that. The idea was just to show the overhead of context switches. > You should start multiple threads and let them read from different > offsets (use pread) and only once they are all started join them all > again. Sure, but doing this directly in Lwt raises other problems: - This means prefetching a large part of the file into the program memory. - The kernel already prefetches files from the disk, so most of the time this is just a memory copy in parallel... - How many threads do we launch in parallel ? This depends on the overhead of context switching between threads, which can not be determined at runtime. I think that the solution with mincore + mmap is better because it uses threads only when really needed. Jérémie