Changing the load balancing algorithm to selecting the node (among k fastest nodes) that has the max jusi number

Changing the load balancing algorithm to selecting the node (among k fastest nodes) that has the max jusi number : https://github.com/DoctorLai/steem-load-balancer/pull/41

The node first checks whether a previously selected node is still valid (i.e., the cached entry hasn’t expired). If it is valid, the request is directly forwarded to that node. Otherwise, the system sends a get_version request to the candidate nodes listed in config.nodes. Among the first config.firstK nodes (default: 1), the node with the highest jussi_num value is selected, cached, and used for subsequent requests.

image.png

PR: Refactor and Add another test when k < 0 https://github.com/DoctorLai/steem-load-balancer/pull/42
PR: Return the max jussi_num node from firstK https://github.com/DoctorLai/steem-load-balancer/pull/41

image.png

Latest image has been updated to docker hub https://hub.docker.com/r/justyy/steem-load-balancer/tags

async function firstKFulfilled(promises, k) { return new Promise((resolve) => { const fulfilled = []; let settledCount = 0; const total = promises.length;
if (k <= 0) return resolve([]);
if (total === 0) return resolve([]);

promises.forEach((p) => {
  Promise.resolve(p)
    .then((value) => {
      fulfilled.push(value);
      if (fulfilled.length === k) {
        resolve(fulfilled); // early resolve once k succeeded
      }
    })
    .catch(() => {})
    .finally(() => {
      settledCount++;
      // if everything has settled and we never reached k
      if (settledCount === total && fulfilled.length < k) {
        resolve(fulfilled);
      }
    });
});

});
}

Steem to the Moon🚀!

Support me, thank you!

Why you should vote me? My contributions
Please vote me as a witness or set me as a proxy via https://steemitwallet.com/~witnesses

image.png