Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T51A6-0004kf-Fv for pgsql-performance@postgresql.org; Fri, 24 Aug 2012 21:11:26 +0000 Received: from wentylator.ang.com.pl ([89.174.215.202]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T51A2-0007mh-B9 for pgsql-performance@postgresql.org; Fri, 24 Aug 2012 21:11:26 +0000 Received: from Artur7 (cfidsl [83.18.105.226]) by wentylator.ang.com.pl (Postfix) with ESMTP id DFE672DD2A1; Fri, 24 Aug 2012 23:11:22 +0200 (CEST) From: =?utf-8?Q?Artur_Zaj=C4=85c?= To: "'Merlin Moncure'" Cc: References: <002401cd8228$ce80e970$6b82bc50$@ang.com.pl> In-Reply-To: Subject: Re: NOTIFY performance Date: Fri, 24 Aug 2012 23:11:08 +0200 Message-ID: <002601cd823c$fbaba070$f302e150$@ang.com.pl> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQFUauSxAaTeqrMVLvYwr9ZuwqP4tAJ9mtt9mEexwmA= Content-Language: pl X-wentylator-MailScanner-Information: Please contact the ISP for more information X-wentylator-MailScanner: Found to be clean X-wentylator-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=0, required 6, autolearn=not spam) X-wentylator-MailScanner-From: azajac@ang.com.pl X-Spam-Status: No X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201208/158 X-Sequence-Number: 47696 >> I would like to create some application using triggers and=20 >> LISTEN/NOTIFY framework. I've tested it, and I noticed that=20 >> performance of NOTIFY significally decreases with increasing number = of=20 >> distinct NOTIFIES in transaction. >> I found that function AsyncExistsPendingNotify is responsibe for it. = I=20 >> think that complexivity of searching duplicates there is O(N^2). = Would=20 >> be possible to improve performance of it? Maybe by using list for=20 >> elements precedence and binary search tree for searching duplicates - = >> with complexivity of O(Nlog2(N)). >> >> I'v tested with 50000 of NOTICES. Updating table with 20000 NOTICES=20 >> when searching is not performed took 1,5 second. With searching it=20 >> took 28 seconds. > >I've confirmed the n^2 behavior on 9.2: >postgres=3D# select pg_notify(v::text, null) from = generate_series(1,10000) v; >Time: 281.000 ms >postgres=3D# select pg_notify(v::text, null) from = generate_series(1,50000) v; >Time: 7148.000 ms > >...but i'm curious if you're going about things the right = way...typically I'd imagine you'd write out actionable items to a table = and issue a much broader NOTIFY which taps listeners on the table to = search the action queue. Could you describe your problem in >a little = more detail? When there was only NOTIFY option with simple channel name there was no = need to send so many messages - creating 50000 channels would be really = stupid. NOTIFY to channel might only mean that there is sth new in table = or sth similar. But with payload option it would be possible to make = simple system for notify other database clients (or self notify - when = changes are made by triggers) that some single record has changed and it = should be invalidated in client cache. I would made (and I already made) = that system (similar to streaming replication :) but more more simple), = but unfortunately even not big update on table would kill my system with = complexivity O(N^2). In general , I know that this system would be not = efficient, but for my application it would simply solve my many = problems. ------------------------------------------- Artur Zajac