Skip to content

Commit

Permalink
mxqd: Avoid user sort when server is full
Browse files Browse the repository at this point in the history
Avoid sorting the user list when we are not going to start a job anyway.
Also save a few source lines and remove a dead initalization.
  • Loading branch information
donald committed Mar 21, 2022
1 parent 5a346dc commit b2e51b9
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,34 +1510,22 @@ static void move_user_to_end(struct mxq_server *server, struct mxq_user_list *us

long start_user_with_least_running_global_slot_count(struct mxq_server *server)
{
struct mxq_user_list *ulist;
unsigned long slots_started = 0;
unsigned long slots_free;
int waiting = 0;
unsigned long df_scratch;

assert(server);

if (!server->user_cnt)
unsigned long slots_free = server->slots - server->slots_running;
if (!server->user_cnt || !slots_free)
return 0;

server_sort_users_by_running_global_slot_count(server);
slots_free = server->slots - server->slots_running;

if (!slots_free)
return 0;

df_scratch=mx_df(MXQ_JOB_TMPDIR_FS "/.");
unsigned long df_scratch=mx_df(MXQ_JOB_TMPDIR_FS "/.");
int waiting = 0;

for (ulist = server->users; ulist; ulist = ulist->next) {
for (struct mxq_user_list *ulist = server->users; ulist; ulist = ulist->next) {
/* if a previous user is waiting for free resources, don't start jobs
* for later users. */
if (waiting && can_start_job_for_user(ulist, df_scratch, server, slots_free))
/* returning -1 here tells the daemon to set its status in the
* database to WAITING, which is just informational. */
return -1;

slots_started = start_user(ulist, slots_free, df_scratch);
unsigned long slots_started = start_user(ulist, slots_free, df_scratch);
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. */
Expand Down

0 comments on commit b2e51b9

Please sign in to comment.