Implement true, per worker, weighted round-robin
Implement true, per worker, weighted round-robin

Based on this psuedo code:
 *
 * Supposing that there is a server set S = {S0, S1,.., Sn-1};
 * W(Si) indicates the weight of Si;
 * i indicates the server selected last time, and i is initialized with -1;
 * cw is the current weight in scheduling, and cw is initialized with zero;
 * max(S) is the maximum weight of all the servers in S;
 * gcd(S) is the greatest common divisor of all server weights in S;
 *
 * while (true) {
 *     i = (i + 1) mod n;
 *     if (i == 0) {
 *         cw = cw - gcd(S);
 *         if (cw <= 0) {
 *             cw = max(S);
 *             if (cw == 0)
 *             return NULL;
 *         }
 *     }
 *     if (W(Si) >= cw)
 *         return Si;
 * }
 *
 * For example, the real servers, A, B and C, have the weights, 4, 3, 2 respectively, a scheduling sequence will be AABABCABC in a scheduling period
 * (mod sum(Wi)).

 *########### The Euclidean Algorithm pseudocode ############
 * Using recursion
 * Using recursion, the algorithm can be expressed naturally:
 *	  function gcd(a, b)
 *	      if b = 0 return a
 *	      else return gcd(b, a mod b)

hamishforbes/lua-resty-upstream