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 1s1kMb-00EYQj-TM for pgsql-general@arkaria.postgresql.org; Tue, 30 Apr 2024 10:05:29 +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 1s1kMX-005ZpX-DV for pgsql-general@arkaria.postgresql.org; Tue, 30 Apr 2024 10:05:26 +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 1s1kMX-005ZpO-0e for pgsql-general@lists.postgresql.org; Tue, 30 Apr 2024 10:05:25 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s1kMV-000pOk-52 for pgsql-general@lists.postgresql.org; Tue, 30 Apr 2024 10:05:25 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-51d2047220cso3498621e87.1 for ; Tue, 30 Apr 2024 03:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714471521; x=1715076321; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=qXlHUAlwrtunpjpTsb+IAFQi+yyoLdLtridMAQ/50bo=; b=CMYOLOaw673TqObJuh3xDSi+DmBsvzELx//AZyHQy/ZV1lIvsqIMm/55x8vK0wxqx+ 10blhETQsfGNqnzJw0WLil7QWItNI4Pz36qKi9ILZ4pIX7XFo18Ga8zBzHUttUClGHRq VSVXRGQrRe/y2TCqqgEswjvhcFzxcSpMI13/xa/XO0tfMF2xL9EG68xxOnbiNCos4Qwv VJaQvBrJV8c0EwbBYJcgcx0k+IbruJP4y8mhfGyxE7/5nTZo+7G0+8r0blZtOv5xZW8+ n+/sN+3N4uTGFf4DyrCNKD4D7gumNLodzTRy70H3r/Pdr0KTpb7WA2JvVaghCQd6EgMO x/dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714471521; x=1715076321; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qXlHUAlwrtunpjpTsb+IAFQi+yyoLdLtridMAQ/50bo=; b=vp/t1+efB3vetUcS/U4M+b7ri5A9sAEqc/8zRk11fd8NgS7r7rFTEvbsW8/aa4VY3A FXJfDSVFeuxO4AT3Q1WshonF6I2ZAjpRhNguzFyO8yH4fYbjG/nu4DX/N1+zWR7XEi8Q L75vjhz1dmq3ALWmUzgZCmgoZKOkoZLUt11huzpYZJLo25t9q8feDHqoj8Xqtl93CNCf B+vy1k4/KZgPSbJpn11kjpVzQ3tuxnrv2WdQYzFGahAGrIvLr3D+0I2TAgYBFVGPYw6e 6NEmH/bBMcCFAz0usEKw6fje+MjNwjnTePXuH1lZ/7rhBpsVrDI9kvDNk85zOS9xYYMW vfiA== X-Gm-Message-State: AOJu0YzY5ymZXKxThzsAD1TT6I4qokSb9U5LmJocX6lbMAlE8yfS340V wQQeYHtPtxkZvTJsAVV1LZ8R07n1ncJTueX0ylej0DEZfu8DhXEflgM4aguavL6TzgZXSvqvrc7 6vrrUqYAN8FCOqF44uAhLBK646kthh1UdqqoWkKM4 X-Google-Smtp-Source: AGHT+IEByE7pK27vJ3ziD85Kt49XndQOY7ZIEBNAfs2HFvB/yjcDaZHy4WN9TYjTLRfp50YODxD37vzm8ZYbJe2eaK8= X-Received: by 2002:a19:914a:0:b0:51c:dffc:41f2 with SMTP id y10-20020a19914a000000b0051cdffc41f2mr6447069lfj.1.1714471520533; Tue, 30 Apr 2024 03:05:20 -0700 (PDT) MIME-Version: 1.0 From: Dimitris Zenios Date: Tue, 30 Apr 2024 13:04:44 +0300 Message-ID: Subject: pg_notify contention To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000f5879306174d81fa" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f5879306174d81fa Content-Type: text/plain; charset="UTF-8" Hi, I am measuring a very simple case of pg_notify in an after update trigger. The trigger is the following: CREATE OR REPLACE FUNCTION audit_event() RETURNS TRIGGER AS $$ BEGIN PERFORM pg_notify('user', 'hello world'); RETURN NULL; END; $$ LANGUAGE plpgsql; and configured on the table with the following sql CREATE CONSTRAINT TRIGGER trigger_test AFTER UPDATE ON pgbench_accounts FOR EACH ROW EXECUTE PROCEDURE audit_event() I am running two benchmarks. One with the pg_notify on the trigger enabled and one with the notify commented out. The command is the following: pgbench -f /tmp/update_bench.sql -c 10 -j 10 -t 100 benchdb And the content of the update_bench.sql are the following \set aid random(1, 100000 * :scale) \set delta random(-5000, 5000) BEGIN; UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid; END; Results are - With pg_notify disabled pgbench (16.1) starting vacuum...end. transaction type: /tmp/update_bench.sql scaling factor: 1 query mode: simple number of clients: 10 number of threads: 10 maximum number of tries: 1 number of transactions per client: 100 number of transactions actually processed: 1000/1000 number of failed transactions: 0 (0.000%) latency average = 11.744 ms initial connection time = 15.616 ms tps = 851.531991 (without initial connection time) - With pg_notify enabled pgbench (16.1) starting vacuum...end. transaction type: /tmp/update_bench.sql scaling factor: 1 query mode: simple number of clients: 10 number of threads: 10 maximum number of tries: 1 number of transactions per client: 100 number of transactions actually processed: 1000/1000 number of failed transactions: 0 (0.000%) latency average = 56.927 ms initial connection time = 11.182 ms tps = 175.664989 (without initial connection time) There is a huge drop in TPS from 851 to 175. I also noticed that if I run the test with a single connection -c 1 then the results are nearly identical which makes me assume that this is a contention that occurs between multiple connections. Thanks --000000000000f5879306174d81fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,=C2=A0

I am measuring a very simple = case of pg_notify in an after update trigger. The trigger is the following:=

CREATE
=C2=A0 =C2=A0 OR REPLACE FUNCTION audit_event() RETURNS T= RIGGER AS
$$
BEGIN
=C2=A0 =C2=A0 PERFORM pg_notify('user',= 'hello world');
=C2=A0 =C2=A0 RETURN NULL;
END;
$$
=C2= =A0 =C2=A0 LANGUAGE plpgsql;

and configured on the= table with the following sql

CREATE CONSTRAINT TR= IGGER trigger_test AFTER UPDATE ON pgbench_accounts FOR EACH ROW EXECUTE PR= OCEDURE audit_event()

I am running two benchmarks. One with the pg_n= otify on the trigger enabled and one with the notify commented out.

= The command is the following:
pgbench -f /tmp/update_bench.sql =C2=A0-c= 10 -j 10 -t 100 benchdb

And the content of the update_bench.sql are= the following

\set aid random(1, 100000 * :scale)=
\set delta random(-5000, 5000)
BEGIN;
UPDATE pgbench_accounts SET= abalance =3D abalance + :delta WHERE aid =3D :aid;
END;

Results are

- With pg_notify disabled

pgbench (16.1)
starting vacuum...end.
transactio= n type: /tmp/update_bench.sql
scaling factor: 1
query mode: simplenumber of clients: 10
number of threads: 10
maximum number of tries:= 1
number of transactions per client: 100
number of transactions actu= ally processed: 1000/1000
number of failed transactions: 0 (0.000%)
l= atency average =3D 11.744 ms
initial connection time =3D 15.616 ms
tp= s =3D 851.531991 (without initial connection time)

=
- With pg_notify enabled

pgbench (16.1)
st= arting vacuum...end.
transaction type: /tmp/update_bench.sql
scaling = factor: 1
query mode: simple
number of clients: 10
number of threa= ds: 10
maximum number of tries: 1
number of transactions per client: = 100
number of transactions actually processed: 1000/1000
number of fa= iled transactions: 0 (0.000%)
latency average =3D 56.927 ms
initial c= onnection time =3D 11.182 ms
tps =3D 175.664989 (without initial connect= ion time)

There is a huge drop in TPS from 851= to 175.

I also noticed that if I run the test wit= h a single connection -c 1 then the results are nearly identical which make= s me assume that this is a contention that occurs between multiple connecti= ons.

Thanks

--000000000000f5879306174d81fa--