Re: queueing via database table? - Mailing list pgsql-general

From Steve Atkins
Subject Re: queueing via database table?
Date
Msg-id AD0E0B23-6AD2-4AE5-BC4D-CB4EB4B1969B@blighty.com
Whole thread Raw
In response to queueing via database table?  (Mark Harrison <mh@pixar.com>)
Responses Re: queueing via database table?  (Richard Huxton <dev@archonet.com>)
Re: queueing via database table?  (Vivek Khera <vivek@khera.org>)
List pgsql-general
On Jan 2, 2007, at 10:34 PM, Mark Harrison wrote:

> I have a cluster of CPUs generating thumbnails for
> a render farm.  I would like to place thumbnail
> requests on a queue, and have the cluster of client
> dequeue the requests and process them.
>
> Of course, each request should be only dequeued once...
> if a thumbnail is being processed by one CPU, it
> shouldn't be processed by another CPU.
>
> Does the following sound like a reasonable approach?
> If not, what's a good way to go?
>
> The processes generating the requests will insert into
> a queue table.  They may add a priority and timestamp.
>
> The several processes servicing the requests will do a
> SELECT FOR UPDATE where ... limit 1, generate thumbnail,
> delete the record and commit.
>
> Comments and suggestions welcome,

Holding a lock while generating the thumbnail doesn't
sound like a great idea, and I think that the select
for update will end up serialising the requests.

I'd add a "rendering" field, text, defaulting
to an empty string.

Then do a "select for update where ... and rendering = '' limit 1",
update the rendering field to the hostname of the box doing the
work and commit. Render the thumbnail. Delete the record.

That'll also give you an easy way to show status of which
box is rendering which scene.

Depending on what else you're putting into the where clause
a partial index on something for records where rendering=''
might be helpful.

Cheers,
   Steve


pgsql-general by date:

Previous
From: Mark Harrison
Date:
Subject: queueing via database table?
Next
From: novnov
Date:
Subject: Re: Generic timestamp function for updates where field