comp.lang.ada
 help / color / mirror / Atom feed
* Buffered I/O with GNAT on Linux
@ 1998-06-14  0:00 Markus Kuhn
  1998-06-14  0:00 ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Kuhn @ 1998-06-14  0:00 UTC (permalink / raw)



The GNAT 3.10p reference manual claims that the Ada.Text_IO is
performed over the stream buffering provided by the C library.
However if I execute under Linux (RH 4.1 and 5.0) the test program

-----------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;

procedure Strange is
begin
   for I in 1 .. 10 loop
      Put("Hello ");
   end loop;
   New_Line;
end Strange;
-----------------------------------------------

and start it with strace to log the system calls, then I get

$ strace ./strange >/dev/null
[...]
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "Hello ", 6)                   = 6
write(1, "\n", 1)                       = 1
_exit(0)                                = ?

which clearly shows that there is no buffering going on and
every single Ada.Text_IO call seems to result in a write system
call.

C is much more efficient here:

$ cat notstrange.c
#include <stdio.h>

int main()
{
  int i;

  for (i = 0; i < 10; i++)
    printf("Hello ");
  printf("/n");
  return 0;
}

$ strace ./notstrange >/dev/null
[...]
write(1, "Hello Hello Hello Hello Hello He"..., 62) = 62
munmap(0x400ac000, 4096)                = 0
_exit(0)                                = ?


The lack of buffering is especially troubelsome for Linux users,
because Linux 2.0 does not have any NFS buffering in the kernel.
Every single write() results immediately in a remote procedure call
to the NFS server. If the NFS server does in addition synchronous
writes (like the DEC one I have to use here does), then a single Put
instruction under Ada requires several hundred milliseconds to
execute. This causes programs such as gnatbind and gnatlink to
execute over 50 times slower if the accessed files are Linux NFS
mounted. Compiling the above test program with gnatmake takes
around 55 seconds in my NFS mounted home directory, but only
around one second in /tmp, which is a local harddisk that enjoys
kernel block buffering.

Is there any trick to get GNAT 3.10p to really use the libc stream
buffering, especially for gnatlink and gnatbind?

Markus

-- 
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org,  home page: <http://www.cl.cam.ac.uk/~mgk25/>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-06-15  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-14  0:00 Buffered I/O with GNAT on Linux Markus Kuhn
1998-06-14  0:00 ` Robert Dewar
1998-06-14  0:00   ` Markus Kuhn
1998-06-15  0:00     ` Tarjei T. Jensen
1998-06-15  0:00     ` Tarjei T. Jensen
1998-06-14  0:00   ` ak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox