I have a ruby daemon that selects 100 records from database and do a task with it.
To make it faster I usually create 3 instances of the same daemon. And each one selects diferents data by using mysql LIMIT
and OFFSET
.
The problem is that sometimes a task is performed 2 or 3 times with the same data record.
So I think that trusting only on database LIMIT
and OFFSET
is not enough ... since 2 or more daemons can actually collects the same data at the same time sometimes.
How can I do it safely? Avoiding 2 instances to select the same data
- Daemon 1 => selects records from 1 to 100
- Daemon 2 => selects records from 101 to 200
- Daemon 3 => selects records from 201 to 300