Re: Processing a work queue

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Alban Hertroys" <alban(at)magproductions(dot)nl>
Cc: "John D(dot) Burger" <john(at)mitre(dot)org>, "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Processing a work queue
Date: 2007-05-01 17:01:16
Message-ID: b42b73150705011001m9c70a24idbe6ce8da4d83a33@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/1/07, Alban Hertroys <alban(at)magproductions(dot)nl> wrote:
> Whether that improves your performance pretty much depends on the queue
> sizes, the frequency of processing and the load processing causes...
> Heh, I just realize we have a work queue table here as well, I'd like to
> know the result.

the optimization here is that we are not updating job.status to flag
which jobs are done or not. this is extremely high concurrency
solution but the advantage is moot if the jobs not extremely short.
you can insert into a completed jobs table but you don't have to check
that to get the next undone job. it might be impractical to do it
this way for real jobs...

thinking about it some more, the only way to skip a job would if the
race condition happened at or near the end of the queue.

> > generating unique number if used with nextval(), setval(), etc. but
> > not necessarily
> > select last_value from s;
> >
> > from point of view of comparing that value with something else and
> > incrementing it if and only if that condition is true in a consistent
> > context.
>
> Indeed, that's one of the weaknesses of last_val. With your example I
> now understand why it even exists, I always thought it an odd and
> dangerous feature.

small clarification here...i'm not acually looking at the lastval
function (get the last returned value by sequence in this session) but
the 'last_value' column of the sequences (get the last value returned
to any session for this sequence. a cooperative lock is the only way
to prevent other sessions from jerking the sequence around via the
'non-mvcc' sequence functions.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brad Nicholson 2007-05-01 17:20:37 Dynamically Allocated System Resources
Previous Message Alban Hertroys 2007-05-01 16:27:47 Re: Processing a work queue