0

I need to send jobs to worker queues according to resource usage and other metrics like how many jobs have been processed and how successful they were.

There is also the need to “weight” these parameters to each other eg that if the success rate drops under an acceptable value others values might me acceptable now?

How would a efficient algorithmic approach look like to implement adaptive routing?

  • Are these algorithms static? Do they change? Do you need to make them programables and updatables in runtime? – Laiv Apr 16 at 16:11
  • They get reported by a pub sub system every second, so there are not static. – Hugo Apr 17 at 8:27
  • You didn't answer my question. The messages go and come, but what about the calculations that decide the routing? Do these calcs/formulas/algorithms change? – Laiv Apr 17 at 8:42
  • The weighting of the metrics could change but i can simple deploy a new version to do that. – Hugo Apr 17 at 13:47
0

Once you've figured out how to consolidate the current statistics you want to incorporate into your adaptive algorithm, it's a matter of consolidating all of that information into a single score.

ordered_queues = queues.sort_by(queue => calculate_suitability(queue.num_processed, queue.num_successful, ...)

ordered_queues.first().send(message)

The suitability score is a weighted function of the inputs that make sense for how you want it scored. The details you'll have to work out for yourself, but I can provide some examples:

double calculate_suitability(num_processed, num_successful, percent_cpu_load) {
    // if the queue hasn't received anything then it is counted as 100% success
    percent_success = num_processed == 0 ? 1.0 : num_successful / num_processed

    // higher success rate is more desirable
    score = percent_success * queue_weight

    // lower cpu usage is more desirable
    score += (1 / percent_cpu_load) * cpu_weight

    return score
}

In the above, the nominal score would be a percentage of suitability. The weights would be there to help normalize the components of the final score. It's also set up so that larger values are more suitable and lower values are less suitable. The weights are there to help temper the results. For example, if CPU load was the most important factor then it might be weighted at 0.75 and the percent correct down at 0.25. If they were equal factors then both weights will be 0.5.

Ideally you want the calculation to be quickly derived from easily obtained numbers. If the process of collecting the metrics you want to use in your suitability calculation takes a long time, then you would probably get better overall results from a simple round robin approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.