Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCXs-00D6pa-0g for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2024 20:21:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rtCXp-00FzJP-RB for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2024 20:21:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCXn-00FzAx-Rj for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2024 20:21:45 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCXe-0018E6-La for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2024 20:21:42 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id A2B7032001FF; Sat, 6 Apr 2024 16:21:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 06 Apr 2024 16:21:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1712434890; x=1712521290; bh=HWGQ+aTTcg 6Fh8B917q3FQVYR95q2S8qAlAIqS+szQo=; b=lrLRrqBnUJQ97A9536hdm1TJZQ Ol8jPd4x5AvahJCA9nTAXaZGrWgE762DLzTLL3W3beIrrVu6BLHDSoT5viEMZTC2 UPV1au3UA83GbRWXlqosi0I6F8VjlIv5RJEHzmzqvn5GWfivbsmYqZmvpEKHNVZ+ hpbVJAGy1BrTUGxChLNEuCmZ1vAonuYwBeNCxE4RVkD7SKnosCGGR+ycuTamWqSH NETvFHRbjvFZLXjiW5+jkX5pN7toOJYewPI5m7h0FrIS5zYr1xjHYJsZZrb79aY5 zzzTmRaqQuGHNn2Gu/Dv9Cy4Us0qVVnNGVW1pg/j3imIOdBxpjLStZYdLvhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712434890; x=1712521290; bh=HWGQ+aTTcg6Fh8B917q3FQVYR95q 2S8qAlAIqS+szQo=; b=kjqvNiWHDWZsbGhuaxjHbMkavR4p/ZOFG96+IOOIsQvA hoq3OnM5mr+wQcCAz4Q0dOGOUL1tIftrgACCogTSFcySc196D2J/2X3K88Uw9sAf mTAyfJ97V13oa5FwCRY4HNijMW3psSL3flf7NnJbwmOuf17R0BH0FuHga9SdV+Ts wtXQxI0vP8A6mrPM7F2yxZtN1qMSqtYIV9QGYaG5n18Q3T1qjv7TEWPgRZBOG41K eqE5h0OJqWSmvoXrLyfT+ql+1iWW5BhGi65u931hDHb/hAW8+xmp7YIRpOQcLFap LyM54GamwLEiSllj8Vbgofv3dw7UqEGRBxAeE7x7eQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegvddgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehmtderredttddvnecuhfhrohhmpeetnhgu rhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtf frrghtthgvrhhnpeekieeugeevudeguedtieefffeivdfgueegkefhfedtveefkefflefg geevhfdujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 Apr 2024 16:21:29 -0400 (EDT) Date: Sat, 6 Apr 2024 13:21:27 -0700 From: Andres Freund To: David Rowley Cc: Melih Mutlu , Jelte Fennema-Nio , PostgreSQL Hackers , Heikki Linnakangas , Robert Haas , Thomas Munro Subject: Re: Flushing large data immediately in pqcomm Message-ID: <20240406202127.2asud6cjfq3exqew@awork3.anarazel.de> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="hhfzgz722x4tyk24" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --hhfzgz722x4tyk24 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On 2024-04-06 14:34:17 +1300, David Rowley wrote: > I don't see any issues with v5, so based on the performance numbers > shown on this thread for the latest patch, it would make sense to push > it. The problem is, I just can't recreate the performance numbers. > > I've tried both on my AMD 3990x machine and an Apple M2 with a script > similar to the test.sh from above. I mostly just stripped out the > buffer size stuff and adjusted the timing code to something that would > work with mac. I think there are a few issues with the test script leading to not seeing a gain: 1) I think using the textual protocol, with the text datatype, will make it harder to spot differences. That's a lot of overhead. 2) Afaict the test is connecting over the unix socket, I think we expect bigger wins for tcp 3) Particularly the larger string is bottlenecked due to pglz compression in toast. Where I had noticed the overhead of the current approach badly, was streaming out basebackups. Which is all binary, of course. I added WITH BINARY, SET STORAGE EXTERNAL and tested both unix socket and localhost. I also reduced row counts and iteration counts, because I am impatient, and I don't think it matters much here. Attached the modified version. On a dual xeon Gold 5215, turbo boost disabled, server pinned to one core, script pinned to another: unix: master: Run 100 100 1000000: 0.058482377 Run 1024 10240 100000: 0.120909810 Run 1024 1048576 2000: 0.153027916 Run 1048576 1048576 1000: 0.154953512 v5: Run 100 100 1000000: 0.058760126 Run 1024 10240 100000: 0.118831396 Run 1024 1048576 2000: 0.124282503 Run 1048576 1048576 1000: 0.123894962 localhost: master: Run 100 100 1000000: 0.067088000 Run 1024 10240 100000: 0.170894273 Run 1024 1048576 2000: 0.230346632 Run 1048576 1048576 1000: 0.230336078 v5: Run 100 100 1000000: 0.067144036 Run 1024 10240 100000: 0.167950948 Run 1024 1048576 2000: 0.135167027 Run 1048576 1048576 1000: 0.135347867 The perf difference for 1MB via TCP is really impressive. The small regression for small results is still kinda visible, I haven't yet tested the patch downthread. Greetings, Andres Freund --hhfzgz722x4tyk24 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="test1a.sh.txt" #!/bin/bash set -e dbname=postgres port=5440 host=/tmp host=localhost test_cases=( "100 100 1000000" # only 100 bytes "1024 10240 100000" # 1Kb and 10Kb "1024 1048576 2000" # 1Kb and 1Mb "1048576 1048576 1000" # all 1Mb ) insert_rows(){ psql -d $dbname -p $port -h $host -c " DO \$\$ DECLARE counter INT; BEGIN FOR counter IN 1..$3 LOOP IF counter % 2 = 1 THEN INSERT INTO test_table VALUES (repeat('a', $1)::text); ELSE INSERT INTO test_table VALUES (repeat('b', $2)::text); END IF; END LOOP; END \$\$; " > /dev/null } psql -d $dbname -p $port -c "CREATE EXTENSION IF NOT EXISTS pg_prewarm;" > /dev/null for case in "${test_cases[@]}" do psql -d $dbname -p $port -h $host -c "DROP TABLE IF EXISTS test_table;" > /dev/null psql -d $dbname -p $port -h $host -c "CREATE UNLOGGED TABLE test_table(data text not null);" > /dev/null psql -d $dbname -p $port -h $host -c "ALTER TABLE test_table ALTER data SET STORAGE EXTERNAL;" > /dev/null insert_rows $case psql -d $dbname -p $port -h $host -c "select pg_prewarm('test_table');" > /dev/null echo -n "Run $case: " elapsed_time=0 for a in {1..5} do start_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') psql -d $dbname -p $port -h $host -c "COPY test_table TO STDOUT WITH BINARY;" > /dev/null end_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') elapsed_time=$(perl -e "printf('%.9f', ($end_time - $start_time) + $elapsed_time)") done avg_elapsed_time_in_ms=$(perl -e "printf('%.9f', ($elapsed_time / 30))") echo $avg_elapsed_time_in_ms done --hhfzgz722x4tyk24--