Answer the question
In order to leave comments, you need to log in
How to build a priority queue like weighted round robin?
For example, we have an array of servers, where the percentage is indicated (balancing weights).
<?php $server = [
's01' => 10/100, // может обработать 10 % задач и текущего стека очереди
's02' => 20/100,
's03' => 25/100,
's04' => 20/100,
's05' => 25/100,
];?>
Answer the question
In order to leave comments, you need to log in
Well, building an array is very simple - first put N1 values of s1 there, then N2 values of s2, and so on.
Something like this:
vector<int> a(100);
for (int i = 0, cur = 0; i < k; ++i ) {
for (int j = 0; j < n[i]; j++) {
a[cur++] = i;
}
}
for (int i = 1; i < 100; i++) {
int j = rand() % (i+1);
swap(a[i], a[j]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question