Re: best way to implement producer/consumer in Perl

From: Joel Burton <jburton(at)scw(dot)org>
To: Vivek Khera <khera(at)kcilink(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: best way to implement producer/consumer in Perl
Date: 2001-05-02 20:21:50
Message-ID: Pine.LNX.4.21.0105021614500.19778-100000@olympus.scw.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2 May 2001, Vivek Khera wrote:

> I've got an application that creates work and posts the work requests
> to a table. Each work request is just a single row in the table.
> I've also got two systems that do the work based on the requests in
> the table.
>
> It seems that ideally, I could use the LISTEN/NOTIFY features to tell
> the consumers when there is work. However, what I really need is a
> blocking LISTEN. That is, it just sits there until it gets a NOTIFY.
>
> Right now, the consumer checks for work every so often, and most of
> the time finds none.
>
> What's the best way to implement such a thing in Perl? Is there a
> blocking LISTEN?

I'm not a serious expert on such things, but, in Perl, LISTEN/NOTIFY is
handled through DBI/DBD, so the LISTEN/NOTIFY notification will come
only when a regular query is sent.

Could you possibly do something like:

while (1) {
execute regular, simple query (eg "SELECT 1;")
check for notification, and handle it
sleep for x minutes/seconds/msecs
}

It's still a loop w/a query, but at least the query should be extremely
speedy and have low impact on DB performance.

If you find a better way, please let me know.

HTH,
--
Joel Burton <jburton(at)scw(dot)org>
Director of Information Systems, Support Center of Washington

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2001-05-02 20:22:06 Re: big pg 6.5 and 7.1 problem in simple application
Previous Message Ryan Mahoney 2001-05-02 20:12:48 Multi Procerssor