Problem Statement as Text - There are T Clients which serves a Server X & below is the configuration.
T0,T1,T2,T3 :--- X0
T4,T5,T6,T7 :--- X1
T8,T9,T10,T11 :--- X2
T12,T13,T14,T15 :--- X3
T0 to T3 Serves in round-robin to X0 Until a threshold of tokens are served Lets Say Eg: Threshold is 9, serving sequence will look like T0,T1,T2,T3,T0,T1,T2,T3,T0
T4 to T7 Serves in round-robin to X1 Until a threshold of tokens are served Lets Say Eg: Threshold is 9, serving sequence will look like T4,T5,T6,T7,T4,T5,T6,T7,T4
T8 to T11 Serves in round-robin to X2 Until a threshold of tokens are served Lets Say Eg: Threshold is 9, serving sequence will look like T8,T9,T10,T11,T8,T9,T10,T11,T8
T12 to T15 Serves in round-robin to X3 Until a threshold of tokens are served Lets Say Eg: Threshold is 9, serving sequence will look like T12,T13,T14,T15,T12,T13,T14,T15,T12
SO SEQUENCE WILL LOOK LIKE THIS
T0,T1,T2,T3,T0,T1,T2,T3,T0 :--- X0
T4,T5,T6,T7,T4,T5,T6,T7,T4 :--- X1
T8,T9,T10,T11,T8,T9,T10,T11,T8 :--- X2
T12,T13,T14,T15,T12,T13,T14,T15,T12 :--- X3
AFTER ITERATING ALL T's NEXT SEQUENCE WILL LOOK LIKE THIS
T1,T2,T3,T0,T1,T2,T3,T0,T1 :--- X0
T5,T6,T7,T4,T5,T6,T7,T4,T5 :--- X1
T9,T10,T11,T8,T9,T10,T11,T8,T9 :--- X2
T13,T14,T15,T12,T13,T14,T15,T12,T13 X3
as you can see , the last used T' is skipped in next iteration.
I managed to write the code snippet code is here, but in my code I am not able to fairly distribute the tokens as expected in table(where last used T' after reaching threshold should be skipped in next iteration).
Please suggest.
#include <iostream>
int CurrentT = 0;
int No_Of_T_Per_X = 4;
int OutputX = 0;
int No_Of_X = 4;
int Valid_T[16] ={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int Processed_Tokens[4] = {0,0,0,0};
int THRESHOLD[4] = {9,9,9,9};
int LastT_Used[4] = {0,0,0,0};
static unsigned int getTargetX(unsigned int id, unsigned int num_T_per_X)
{ return id / num_T_per_X; }
bool batch = false;
int main()
{
int prev_SPMindex = -1;
int next_SPMindex = 0;
for(int i=1;i<=1000;i++) { // Looping to test some random no. of tokens..
if ( Processed_Tokens[OutputX] >= THRESHOLD[OutputX]){
THRESHOLD[OutputX] = THRESHOLD[OutputX] + 9;
//LastT_Used[OutputX] = CurrentT;
prev_SPMindex = next_SPMindex;
CurrentT = prev_SPMindex;
}
CurrentT = (CurrentT + 1) % (sizeof(Valid_T)/sizeof(int)); // Currently Processed T'
if(((CurrentT % No_Of_T_Per_X) == 0)){
next_SPMindex = CurrentT -1;
CurrentT = prev_SPMindex;
CurrentT = (CurrentT + 1) % (sizeof(Valid_T)/sizeof(int));
}
OutputX = getTargetX(Valid_T[CurrentT], No_Of_T_Per_X); // Currently Processed X'
Processed_Tokens[OutputX] += 1; // Increasing the Count of Tokens to test
}
return 0;
}
Problem statement in figures Round-Robin Distribution
expected Output Table for distribution. Expected Output Table
Aucun commentaire:
Enregistrer un commentaire