Re: NOTIFY performance

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Artur Zając <azajac(at)ang(dot)com(dot)pl>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: NOTIFY performance
Date: 2012-08-24 19:12:05
Message-ID: CAHyXU0x5r+3zL6WYpHmuHhONatGYG3f49sdx+2z4Jjc2FhNBxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Aug 24, 2012 at 1:46 PM, Artur Zając <azajac(at)ang(dot)com(dot)pl> wrote:
> Hello,
>
>
> I would like to create some application using triggers and LISTEN/NOTIFY
> framework. I've tested it, and I noticed that performance of NOTIFY
> significally decreases with increasing number of distinct NOTIFIES in
> transaction.
> I found that function AsyncExistsPendingNotify is responsibe for it. I think
> that complexivity of searching duplicates there is O(N^2). Would be possible
> to improve performance of it? Maybe by using list for 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 when
> searching is not performed took 1,5 second. With searching it took 28
> seconds.

I've confirmed the n^2 behavior on 9.2:
postgres=# select pg_notify(v::text, null) from generate_series(1,10000) v;
Time: 281.000 ms
postgres=# 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?

merlin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2012-08-24 19:40:57 Re: Loose Index Scans by Planner?
Previous Message Artur Zając 2012-08-24 18:46:42 NOTIFY performance