Version française
Home     About     Download     Resources     Contact us    
Browse thread
Asynchronous IO programming in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jérémie Dimino <jeremie@d...>
Subject: Re: [Caml-list] Asynchronous IO programming in OCaml
On Mon, Oct 25, 2010 at 10:42:05AM +0200, Goswin von Brederlow wrote:
> Doesn't that mean you have to do polling of all pending I/O? That seems
> horrible ineficient (you check them all every time) or slow I/Os can
> starve quick ones (you only check the oldest ones).

No. In the current implementation, when we want to read a file, we mmap
it, then test it with mincore. If it is not cached in memory, we first
wait a bit, test again and if it is still not available, we launch a
thread which try to read the first byte of the mmapped buffer.

If the file is not cached, then the time needed to launch a thread is
negligible compared to the time needed to fetch data from the disk.

> The nice thing about libaio is that you get events as I/O completes and
> you get many events in one simple syscall. Doing thousands of I/O
> requests in parallel is trivial there.

AFAIK libaio is linux-specific and not impelemted for all
filesystems. Moreover it transparently fallback to synchronous IOs when
asynchronous IOs are not available, so there is no reliable way to test
whether IOs will block or not.

Jérémie