Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Database queue logic

by Ben Win Lue (Friar)
on Jun 14, 2005 at 12:12 UTC ( [id://466499]=note: print w/replies, xml ) Need Help??


in reply to Database queue logic

I would add a timestamp column to my process list.
Any process would:
  • select all processes that have a null timestamp or a timestamp that's older than 10* Minutes
  • update all selected processes with the timestamp of now.
  • process all selected processes
  • delete processed processes

*the 10 Minutes are subject to fiddling

Replies are listed 'Best First'.
Re^2: Database queue logic
by moot (Chaplain) on Jun 14, 2005 at 14:34 UTC
    You're still racing between the select and the update, although something like this might work:

    • Update records where 'owner' column is null, with *my* value and timestamp now().
    • Select records with my owner value *or* where timestamp is older than threshold. This catches the case where some records have gone stale because a process died or what-have-you.
    • Process & delete selected records.
    This way you're letting the database server handle updating the correct records. Depending on how speedily new records are added to the queue, it seems likely that processes will be working with records more than waiting for selects. Of course this approach doesn't help with splitting the records evenly between processes, but neither will a mutex.
      Good solution,

      I will try this approach shortly.

      Thanks all!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://466499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found