<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2005/05/1bf5c026db2f809e0c5de3be7859547d"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2005-05-25T10:30:53"
  subject="Re: [Caml-list] Re: Efficient I/O with threads"
  prev="2005/05/6b8b6486de181a32ff80a0d9ff3f965c"
  next="2005/05/8c447cfccabf8b2db4a82680e52f5a96"
  prev-in-thread="2005/05/862042e593e450d6eee4b134aaf7cd07"
  prev-thread="2005/05/9286991d81ae52bf3d33cf5e71230358"
  next-thread="2005/05/9b4cbf578590a187898d9b32c31ff96e"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Efficient I/O with threads">
<msg 
  url="2005/05/7b8093e8e88d0016895e22b0392933a7"
  from="Yaron Minsky &lt;yminsky@g...&gt;"
  author="Yaron Minsky"
  date="2005-05-24T22:14:47"
  subject="Efficient I/O with threads">
<msg 
  url="2005/05/d1f9f154a34cfa4f9b5d1ecc7da6bca7"
  from="Yaron Minsky &lt;yminsky@g...&gt;"
  author="Yaron Minsky"
  date="2005-05-25T01:42:23"
  subject="Re: Efficient I/O with threads">
<msg 
  url="2005/05/862042e593e450d6eee4b134aaf7cd07"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2005-05-25T02:13:40"
  subject="Re: [Caml-list] Re: Efficient I/O with threads">
</msg>
<msg 
  url="2005/05/1bf5c026db2f809e0c5de3be7859547d"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2005-05-25T10:30:53"
  subject="Re: [Caml-list] Re: Efficient I/O with threads">
</msg>
</msg>
</msg>
</thread>

<contents>
Am Dienstag, den 24.05.2005, 21:42 -0400 schrieb Yaron Minsky:
&gt; An addendum.  One thing that was pointed out to me in some private
&gt; emails was that buffering could solve the problem on the reading side
&gt; as well.  That is true, as far as it  goes --- that's why I said that
&gt; I can't think of a _clean_ way of handling it.  One of the nice things
&gt; about ocaml IO channels is that they handle buffering, and it seems a
&gt; shame to have to reimplement buffering on top of them.
&gt; 
&gt; Put another way, the problem with input/output channels appears to be
&gt; that the buffering is done on the wrong side of the lock.  You
&gt; shouldn't have to do any locking to do IO when the request can be
&gt; satisfied from the buffer.  The fact that IO channels always require
&gt; you to acquire the lock means that the performance is crappy unless
&gt; you bundle up writes by yourself.
&gt; 
&gt; Fixing this is perhaps too deep of a change to drive into the OCaml
&gt; system at this point.  Is this a problem that is addressed by the I/O
&gt; channels provided by any other library such as extlib?

I just looked into the sources of the OCaml runtime. The additional work
to lock/unlock the I/O channels is very, very small, just a
pthread_mutex_lock and a pthread_mutex_unlock for every operation. What
counts more is the general overhead for the multi-threading machinery.
For every blocking system call a lot of additional overhead is
necessary.

As an alternative, you can try the object channels of Ocamlnet. With

let in_ch =
  Netchannels.lift_in (`Raw (new Netchannels.input_descr in_fd))

and

let out_ch =
  Netchannels.lift_out (`Raw (new Netchannels.output_descr out_fd))

you get object channels over the file descriptors in_fd, out_fd that
implement buffers by O'Caml code and work much like the built-in
channels. These channels aren't protected against concurrent usage, and
may be more light-weight because of this.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------


</contents>

</message>

