From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludovic.courtes@inria.fr (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: RPC performance Date: Thu, 22 Jun 2017 18:05:07 +0200 Message-ID: <87injoc8jw.fsf@inria.fr> References: <20170527105641.9426-1-mail@cbaines.net> <20170527123113.1ca668e7@cbaines.net> <87tw424cap.fsf@gnu.org> <87fufhkw85.fsf@gnu.org> <871sr0ok2h.fsf@gnu.org> <8760gbh2th.fsf@gnu.org> <87efuym57c.fsf@gnu.org> <87a85kt7ad.fsf_-_@gnu.org> <87a85hnvqm.fsf@gnu.org> <87tw3lyz7t.fsf@inria.fr> <87poe4c5y9.fsf_-_@gnu.org> <87fuezkquf.fsf@gnu.org> <87lgoq8ch8.fsf@gnu.org> <87k2497kk7.fsf@elephly.net> <87vans1k5e.fsf_-_@inria.fr> <87poe01jgo.fsf@gnu.org> <87o9tg5dbm.fsf@igalia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dO4bz-0000dI-ED for guix-devel@gnu.org; Thu, 22 Jun 2017 12:05:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dO4bu-0003rW-Gb for guix-devel@gnu.org; Thu, 22 Jun 2017 12:05:39 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:63402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dO4bu-0003pF-6i for guix-devel@gnu.org; Thu, 22 Jun 2017 12:05:34 -0400 In-Reply-To: <87o9tg5dbm.fsf@igalia.com> (Andy Wingo's message of "Thu, 22 Jun 2017 16:03:57 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Andy Wingo Cc: guix-devel@gnu.org Heya, Andy Wingo skribis: > On Mon 19 Jun 2017 10:15, ludovic.courtes@inria.fr (Ludovic Court=C3=A8s)= writes: > >> +(define (buffering-output-port port buffer) >> + ;; Note: In Guile 2.2.2, custom binary output ports already have thei= r own >> + ;; 4K internal buffer. >> + (define size >> + (bytevector-length buffer)) >> + >> + (define total 0) >> + >> + (define (flush) >> + (put-bytevector port buffer 0 total) >> + (set! total 0)) >> + >> + (define (write bv offset count) >> + (if (zero? count) ;end of file >> + (flush) >> + (let loop ((offset offset) >> + (count count) >> + (written 0)) >> + (cond ((=3D total size) >> + (flush) >> + (loop offset count written)) >> + ((zero? count) >> + written) >> + (else >> + (let ((to-copy (min count (- size total)))) >> + (bytevector-copy! bv offset buffer total to-copy) >> + (set! total (+ total to-copy)) >> + (loop (+ offset to-copy) (- count to-copy) >> + (+ written to-copy)))))))) >> + >> + (let ((port (make-custom-binary-output-port "buffering-output-port" >> + write #f #f flush))) >> + (setvbuf port _IONBF) >> + port)) >> + > > Why not just set to _IOFBF and let Guile 2.2's buffering handle it? Because we want controlled buffering when writing (we need to flush pending output when we=E2=80=99re done writing the RPC request), and no buffering at all when reading. In C/C++ the way to do that is to have unbuffered streams and to do application-level buffering by allocating output buffers of the right size. Thoughts? Ludo=E2=80=99.