/// <summary> ///weighted round robin algorithm/// </summary> Public Static classWeightroundrobin {Private Static Objectobj =New Object(); Private Static intpos =0; Staticdictionary<string,int> dic =Newdictionary<string,int> { { "192.168.1.12",1}, {"192.168.1.13",1 }, { "192.168.1.14",3}, { "192.168.1.15",1}, {"192.168.1.16",1}, {"192.168.1.17",1 }, { "192.168.1.18",1}, { "192.168.1.19",1} }; Public Static stringRoundrobin () {//Access IP Listlist<string> it =DiC. Keys.tolist (); List<String> serverlist =Newlist<string>(); foreach(varIteminchit) { intWeight =0; Dic. TryGetValue (item, outweight); for(inti =0; I < weight; i++) {Serverlist.add (item); } } stringServer =NULL; Lock(obj) {if(Pos >=serverlist.count) {pos=0; } Server=Serverlist[pos]; POS++; } returnserver; } }
Load Balancing algorithm (two) weighted polling load balancing algorithm