Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsepI-0002jN-U3 for pgsql-general@arkaria.postgresql.org; Tue, 07 Jul 2020 04:03:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jsepG-00073Y-Cs for pgsql-general@arkaria.postgresql.org; Tue, 07 Jul 2020 04:03:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsepG-00073P-2B for pgsql-general@lists.postgresql.org; Tue, 07 Jul 2020 04:03:22 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jsep9-0005Yf-5G for pgsql-general@postgresql.org; Tue, 07 Jul 2020 04:03:20 +0000 Received: by mail-qt1-x841.google.com with SMTP id e12so30738637qtr.9 for ; Mon, 06 Jul 2020 21:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7jzUKLdSnDofVEqnhp4+Dge/R0YAkUoKFtRLrTfFrLY=; b=W46bIt999fEoSF2Be6gFZUCcQRhKYQz9dUtrepO25az7VSgUOQzEWzXSM0za09qwID 5zjQdM/gcmCE4j/bAJ/3ec9onNCqPOA24zvFQH2+9LTsFh4BFU0b0Fd683ktJffw57Q8 FykhLIW6NbY7e8fVT+QFOCT6+lz+KpLXpa9wBonEzI0AGbNvSsUVqBGnzZ3nWLugLfns SjVZGfKFUa9/q8sPvXFsI3lkU8Wt0njPu9t8K3eLe8VpeQOU3iCnhQEI73yA2frcOaGY MU2vQl6u3NyMPzuCyZHFbwjJInQ6UGbFPrPluL2QqOfjxyb0EaQfJUCtbp87UBz9jIHx N5fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=7jzUKLdSnDofVEqnhp4+Dge/R0YAkUoKFtRLrTfFrLY=; b=SF3Ov+Ck1kacIbzR9S2t4rHyE6K8qT0WxgeoJsl0tiStUhXx2PJ94q0AcgyrtnEYTG WmA5ohyEWDypOIKtglyKZh0fAs11prWp8Tq8ZjBA7onNVGkw/A0/npSlSCtQvaPQFOPE 2xgWwE4JUJ41wvFkAViQg8mgMi8KpAAk2WzGCInWEwEpZW/ZNxLZ4zhzD+dCSYqIyXif 0X4qqASoPu57cb+lO6FdQR3Ps+ndFUkU0WkQ60TF/oKBC+0a/jMQhte2JNKWR/3NUKf7 JYZQuHaDSlBsdHINSj35ot7vmKvtTjuJFn5RyGrpIIZvKXNtrzQpQTkycluES0uqd3sk +DQQ== X-Gm-Message-State: AOAM5311UrNqxyARJya1Oe764NCth2VVpX+fvfqsFM1tdWTJNUs32UuU GkdW7TAHii2opx70OWP5INKXkYJByHjLEtxXz+A= X-Google-Smtp-Source: ABdhPJwKzZl60D1NLKk7HowGKta5dSzY9VlytQNsUtTsjPgkzb+MWVeo5/YtPtVmmwwpIaW88gOJil+mafDs3WnMlu8= X-Received: by 2002:ac8:1088:: with SMTP id a8mr21763842qtj.90.1594094593992; Mon, 06 Jul 2020 21:03:13 -0700 (PDT) MIME-Version: 1.0 References: <70948.1593268822@sss.pgh.pa.us> <322743.1593439560@sss.pgh.pa.us> In-Reply-To: From: Samuel Williams Date: Tue, 7 Jul 2020 16:03:03 +1200 Message-ID: Subject: Re: libpq pipelineing To: Tom Lane Cc: "David G. Johnston" , pgsql-general Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Here are some initial numbers. DB::Client Warming up -------------------------------------- db-postgres 281.000 i/100ms db-mariadb 399.000 i/100ms mysql2 533.000 i/100ms pg 591.000 i/100ms Calculating ------------------------------------- db-postgres 2.725k (=C2=B1 1.8%) i/s - 13.769k in 5.053= 750s db-mariadb 3.990k (=C2=B1 2.4%) i/s - 19.950k in 5.002= 453s mysql2 5.153k (=C2=B1 4.7%) i/s - 26.117k in 5.079= 570s pg 5.772k (=C2=B1 4.4%) i/s - 28.959k in 5.027= 423s Comparison: pg: 5771.7 i/s mysql2: 5152.8 i/s - 1.12x (=C2=B1 0.00) slower db-mariadb: 3990.3 i/s - 1.45x (=C2=B1 0.00) slower db-postgres: 2725.5 i/s - 2.12x (=C2=B1 0.00) slower The db-* gems are event driven. However, that is of less interest right now= . This benchmark creates a table, inserts 1000 (or some fixed number) of rows, and then selects them all back out. What I noticed is that `PQgetvalue` and `PQgetisnull` is not particularly efficient, at least via FFI. Requires rows * columns * 2 FFI calls. libmariadb provides `mysql_fetch_row` which returns a `char **` per row. Requires only rows FFI calls. Does a similar method exist for libpq? e.g. `PGgetrow(index) -> char**` (array of strings, one for each column, may be nil to indicate null). Kind regards, Samuel On Tue, 30 Jun 2020 at 12:50, Samuel Williams wrote: > > Tom, I'm implementing a small abstraction layer for event-driven > result streaming on PostgreSQL and MariaDB for Ruby, and I'll endeavor > to report back with some numbers once I have enough of it working to > benchmark something meaningful. > > Thanks for your patience and help. > > Kind regards, > Samuel > > On Tue, 30 Jun 2020 at 02:06, Tom Lane wrote: > > > > Samuel Williams writes: > > > Those methods don't seem to have an equivalent in libpq - you can use > > > PQgetResult but it buffers all the rows. Using single row mode result= s > > > in many results for each query (seems like a big overhead). > > > > Have you got any actual evidence for that? Sure, the overhead is > > more than zero, but does it mean anything in comparison to the other > > costs of data transmission? > > > > > Maybe the statement about efficiency is incorrect, but it would be > > > nice if you could incrementally stream a single result set more > > > easily. > > > > More easily than what? If we did not construct a PGresult then we woul= d > > need some other abstraction for access to the returned row, dealing wit= h > > error cases, etc etc. That would mean a lot of very duplicative API co= de > > in libpq, and a painful bunch of adjustments in client code. > > > > regards, tom lane