Skip to content

Commit

Permalink
plugin: initialize factor weights on plugin load
Browse files Browse the repository at this point in the history
Problem: The weight of each factor is checked every time the priority of
a job is calculated. It would be cleaner to put this check somewhere
else so it does not need to be repeated.

Create defaults for the weights of each factor used in the priority
calculation of a job. Initialize each weight when the plugin is loaded.
In the callback for conf.update, check to see if these weights have been
configured; if not, continue to use the defaults defined at the top of
the file.
  • Loading branch information
cmoussa1 committed Jun 6, 2024
1 parent 72dbce4 commit 932c6d1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/plugins/mf_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ extern "C" {
// flux-accounting
#define BANK_INFO_MISSING 999

// default weights for each factor in the priority calculation for a job
#define DEFAULT_FSHARE_WEIGHT 100000
#define DEFAULT_QUEUE_WEIGHT 10000
#define DEFAULT_AGE_WEIGHT 1000

std::map<int, std::map<std::string, Association>> users;
std::map<std::string, Queue> queues;
std::map<int, std::string> users_def_bank;
Expand Down Expand Up @@ -75,11 +80,6 @@ int64_t priority_calculation (flux_plugin_t *p,
fshare_weight = priority_weights["fairshare"];
queue_weight = priority_weights["queue"];

// check values of priority factor weights; if not configured,
// these will be set to -1, so just use default weights
if (fshare_weight == -1) fshare_weight = 100000;
if (queue_weight == -1) queue_weight = 10000;

if (urgency == FLUX_JOB_URGENCY_HOLD)
return FLUX_JOB_PRIORITY_MIN;

Expand Down Expand Up @@ -201,8 +201,8 @@ static int conf_update_cb (flux_plugin_t *p,
}

// assign unpacked weights into priority_weights map
priority_weights["fairshare"] = fshare_weight;
priority_weights["queue"] = queue_weight;
if (fshare_weight != -1) priority_weights["fairshare"] = fshare_weight;
if (queue_weight != -1) priority_weights["queue"] = queue_weight;

return 0;
}
Expand Down Expand Up @@ -1108,6 +1108,11 @@ extern "C" int flux_plugin_init (flux_plugin_t *p)
< 0)
return -1;

// initialize the weights of the priority factors with default values
priority_weights["fairshare"] = DEFAULT_FSHARE_WEIGHT;
priority_weights["queue"] = DEFAULT_QUEUE_WEIGHT;
priority_weights["age"] = DEFAULT_AGE_WEIGHT;

return 0;
}

Expand Down

0 comments on commit 932c6d1

Please sign in to comment.