SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    implementing simple round-robin

    hi i have an ascending array of Users with there ID's . I want to assign a job in a cycle to each user..... that is , first job to U1, second to U2 , thrid to U3.

    my problem is that , when second job comes & at the same time U1 completes it's job , that second job again get assigned to U1 instead of U3.

    how can i modify my algorithm

  2. #2
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paragdiwan View Post
    hi i have an ascending array of Users with there ID's . I want to assign a job in a cycle to each user..... that is , first job to U1, second to U2 , thrid to U3.

    my problem is that , when second job comes & at the same time U1 completes it's job , that second job again get assigned to U1 instead of U3.

    how can i modify my algorithm
    Well a rough idea is to maintain two que for user to avoid race condition among users.Once task is assigned it should go to active_user and after finishing the task it should go to waiting_que and task should be assigned from the array u are maintain.
    you have to maintain the extra logic to maintain the user in these arrays

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by priti View Post
    Well a rough idea is to maintain two que for user to avoid race condition among users.Once task is assigned it should go to active_user and after finishing the task it should go to waiting_que and task should be assigned from the array u are maintain.
    you have to maintain the extra logic to maintain the user in these arrays
    Thanx priti for replying.

    but problem is how i implement Queue using database. ? that is worrying me.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    select id 
       from users 
       where no_job_assigned OR user_has_the_job_completed 
       order by id
    This will select the first user without a job

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You could stick a timestamp field in your user table, or create a new table called user_job

    That could contain:
    user_id
    timestamp

    That way on each job arriving you'd get the highest time (ie the previous job), and the user_id that did that job, then add 1 to user_id.

    I can think of some ways this would go bad though, what if your last job was allocated to user_id1 and you had previously deleted user_id2, youd have to be able to continue on to user_id3.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •