[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: output streams vs output ports



From: Michael Sperber <sperber@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: output streams vs output ports
Date: Tue, 21 Jun 2005 09:43:50 +0200

> Shiro Kawai <shiro@xxxxxxxx> writes:
> 
> > The simple-minded copy program:
[snip]
> > It runs 3.5x faster if I bypass locking of 'in' and 'out' ports
> > in Gauche.
> 
> Could you selectively bypass the locking of only the input port so we
> get a better idea what the specific issue with the output port is?

Yes.  These are elapsed time for various conditions,
repeating the program 10 times.  System time was less than 10ms.

lock both         : 3.64s
lock output only  : 2.42s
lock input only   : 2.26s
no locking        : 1.04s

In the current implementation, a port has a recursive lock and
the pthread_mutex_lock is called when a builtin I/O procedure
is called and the calling thread hasn't acquired the lock.  So
the locking doesn't affect the large-granularity operation
such as read or write much, while it is expensive for fine-grained
operation such as read-char/write-char expensive.  Gauche
provides a procedure "with-port-locking" to lock the port in
larger granularity, which is what I used to "bypass" the
locking.

(Maybe I'm doing something stupid; if there's a clever way to
avoid this much of locking overhead, I'd like to be enlightened.)

--shiro