MySQL Concurrent Updates
Hello,
I have a database question and would value some input from more experienced MySQL users;
I have two programs (one of which I would like to run on more than one computer). The model is a producer and then 1+ workers. All programs written in Java.
The producer downloads some information and stores it in a database. This happens at unpredictable times.
The workers process the new data in the database, before changing it slightly (including setting a flag that says that data was successfully processed). Currently the 1 worker just works in a loop. It does a select and gets all the unprocessed data. Processes it and then does another select to see if new data has arrived. If not it waits for a while before trying again.
So, the processing takes a while. about 2mins per data point there are about 11000 data points and its going up. So we need more horsepower....
If I run more than 1 worker on more than 1 computer then I have a problem that I need help with. Worker 1 does select gets list of unprocessed data. Worker 2 does the same gets a similar list, they end up processing the same data some of the time. FAIL. Is there an SQL solution to this problem? Only request one data point at a time and somehow flag the row? Seems rubbish. Or should I make another program that gives tasks out to the workers... sort of a man in the middle?
I am guessing that this sort of access problem is solved pretty well for databases?
I have written distributed systems before but not ones that use a MySQL table to store the data and results and has computers putting in new data that are not even on the same network....
Cheers,
Phil
|