Skip to content

Commit

Permalink
mxqd: Implement round-robin for equal users
Browse files Browse the repository at this point in the history
Move a user, for whom a job was started, to the end of the user list.
This way the server will do round-robin between users who have otherwise
equal precedence based on running_global_slot_count.
  • Loading branch information
donald committed Mar 20, 2022
1 parent cf98592 commit 70c8bee
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,23 @@ static int could_potentially_start_job_for_user(struct mxq_user_list *user) {
return 0;
}

static void move_user_to_end(struct mxq_server *server, struct mxq_user_list *user) {
struct mxq_user_list **ptr;

if (!user->next)
return;

ptr = &server->users;
while (*ptr != user)
ptr = &(*ptr)->next;
*ptr = user->next;
ptr = &(user->next->next);
while (*ptr)
ptr = &(*ptr)->next;
*ptr = user;
user->next = NULL;
}

long start_user_with_least_running_global_slot_count(struct mxq_server *server)
{
struct mxq_user_list *ulist;
Expand Down Expand Up @@ -1524,8 +1541,12 @@ long start_user_with_least_running_global_slot_count(struct mxq_server *server)
return -1;

slots_started = start_user(ulist, slots_free, df_scratch);
if (slots_started)
if (slots_started) {
/* move user to end of list so that we get a round-robin with with
* other users which sort to the same precedence. */
move_user_to_end(server, ulist);
return slots_started;
}

if (waiting)
continue;
Expand Down

0 comments on commit 70c8bee

Please sign in to comment.