Re: Listen / Notify rewrite

From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Joachim Wieland <joe(at)mcknight(dot)de>, Merlin Moncure <mmoncure(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Andrew Chernow <andrew(at)esilo(dot)com>
Subject: Re: Listen / Notify rewrite
Date: 2009-11-14 00:14:28
Message-ID: 4AFDF664.4030007@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Josh Berkus wrote:
> Payloads are also quite useful even in a lossy environment, where you
> understand that LISTEN is not a queue. For example, I'd like to be
> using LISTEN/NOTIFY for cache invalidation for some applications; if it
> misses a few, or double-counts them, it's not an issue. However, I'd
>
Not sure how missing a few can not be an issue for cache invalidation,
but never mind.

In the use-cases I've considered I've used a trigger to write a change
notification to a table
and a notify to indicate that notification record(s) have been changed.
The notifications
contain copies of the primary keys and the action so the cache processor
knows what's
changed and the notify is a a wakeup signal.

If this is in fact the most common use case, perhaps an alternative
approach would be
to automate it directly, so that writing the triggers (and using the
trigger processing engines)
would be unecessary, so:
- the queue definition can be automated with reference to the parent
table, by DDL stating
that one is required
- the notification 'name' is effectively the queue name and the
subscription says 'tell me
when a change note is placed in the queue'

Doing this in the database engine core allows a number of potential
optimisations:
- the mechanism does not require general trigger execution
- the queue does not have to be a real table, and can have custom
semantics: it may not
actually be necessary to store copies of the primary key data if it
can refer to the rows
so the data can be retrieved as the queue is consumed
- if there are no subscribers to the queue then the insertion to it can
be elided
- if the server crashes, connected consumers should assume caches are
invalid and
theer is no ACID requirement for the queue data
- if the queue fills then slow consumer(s) can be dropped and can
receive a data loss
indicator
> like to be able to send message like players_updated|45321 where 45321
> is the ID of the player updated.
>
Indeed.

Just a thought, anyway. (FWIW I was initially concerned about the lack
of payload, but
with any sort of lossy compression I figured it wasn't, actually, and I
needed a notification
queue)

James

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2009-11-14 00:39:45 Re: tsearch parser inefficiency if text includes urls or emails - new version
Previous Message Tom Lane 2009-11-14 00:08:22 ALTER ROLE/DATABASE RESET ALL versus security