Link to home
Start Free TrialLog in
Avatar of CarlosScheidecker
CarlosScheidecker

asked on

How to garantee that different client threads work on different subsets of data

Hello,

I have a table of 1.000 Urls. I also have 4 clients that need to work on those URLs at the same time. I would like to garantee that each client works on unique URLs. Meaning, I want to divide that by four so that each one has 250 URLs to work with. Those URLs change. What I would like to do is to do some sort of locking on a subset of URLs so that only that client can read those 250 URLs with a select * form tbl_URL while the others can only do the same within their set.

I need to make sure that no 2 clients process the same URLs.

Once the URL is processed, it can be relased back to the pool.

How can I do that?

Thanks.
Avatar of CarlosScheidecker
CarlosScheidecker

ASKER

What I thought so far was:

1) Pass two values to the client: client number and total number of clients.
2) Perform a count and divide from the total number of clients.
3) Once I have the size of one chunk, then I can do a limit with start index and number of total rows to fetch,

4) The start index will be number of client - 1, times the chunk. If client is client one, than 0 times chunk  equal to index 0. If client is 2, then 1 times chuk size gives the start index.

Since URLs not only change on their size but can be edited, I cannot do those SQL statically.

Any other ideas?
In case you do this from a free programmable application I´d insert a 'lock' flag into the table setting the userid as lock or '0' as default (better performance on indeices rather than NULL).
Combine that with your ideas and you should be good to give it a go.
I do not want to lock the table or a set of tuples. I think this will be a problem while writing to it.
This is not about DB level table locks.
All you do is to expand the table for a column like 'work_lock'. All you do is to fire up an SQL to insert the userid into 250 rows, column work_lock. Do the insert into tables that do not have a work_lock set.
All users will be able to work with data from this table this way. As soon as work on a row has been done, reset the column back to NULL or whatever and everything is fine.
ASKER CERTIFIED SOLUTION
Avatar of CarlosScheidecker
CarlosScheidecker

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is the answer to that question. Tried and worked fine.