Re: Listen / Notify rewrite

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Joachim Wieland <joe(at)mcknight(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, Andrew Chernow <andrew(at)esilo(dot)com>
Subject: Re: Listen / Notify rewrite
Date: 2009-11-12 15:48:44
Message-ID: 407d949e0911120748p6c920803q312cf7234de3f4b5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 12, 2009 at 3:09 PM, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>>
>> What advantage is there in limiting it to a tiny size? This is a
>> 'payload' after all...an arbitrary data block. Looking at the patch I
>> noticed the payload structure (AsyncQueueEntry) is fixed length and
>> designed to lay into QUEUE_PAGESIZE (set to) BLCKSZ sized pages.
>>
>
> Hmmmm. Looks like the limitation comes from slru. The true payload limit
> is (8K - struct members) the way this is implemented.

So I'm beginning to think that adding a "payload" to NOTIFY is a bad
idea altogether.

The original use case NOTIFY was designed to handle was to implement
condition variables. You have clients wait on some data structure and
whenever someone changes that data structure they notify all waiting
clients to reread the data structure and check if their condition is
true. The condition might be that the data structure doesn't match
their locally cached copy and they have to rebuild their cache, it
might be that some work queue is non-empty, etc.

So the way to build a queue would be to use a table to hold your work
queue and then use NOTIFY whenever you insert into the queue and any
idle workers would know to go dequeue something from the queue.

It sounds like what people are trying to do is use NOTIFY as a queue
directly. The problem with this is that it was specifically not
designed to do this. As evidenced by the fact that it can't store
arbitrary data structures (nothing else in postgres is limited to only
handling text data, this would be an annoying arbitrary limitation),
can't handle even moderately large data efficiently, etc.

I'm beginning to think the right solution is to reject the idea of
adding a payload to the NOTIFY mechanism and instead provide a queue
contrib module which provides the interface people want.

--
greg

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2009-11-12 15:55:13 array_to_string bug?
Previous Message Tom Lane 2009-11-12 15:45:45 Re: recovery is stuck when children are not processing SIGQUIT from previous crash