lib/rpc-client/router.js
function laRoute(client, serverType, msg, cb) {
    const servers = client._station.serversMap[serverType];
    if (!servers || !servers.length) {
        utils.invokeCallback(cb, new Error(`rpc servers not exist with serverType: ${serverType}`));
        return;
    }
    const actives = [];
    if (!client.laParam) {
        client.laParam = {};
    }
    if (client.laParam[serverType]) {
        for (let j = 0; j < servers.length; j++) {
            let count = client.laParam[serverType][servers[j]];
            if (!count) {
                count = 0;
                client.laParam[servers[j]] = 0;
            }
            actives.push(count);
        }
    } else {
        client.laParam[serverType] = {};
        for (let i = 0; i < servers.length; i++) {
            client.laParam[serverType][servers[i]] = 0;
            actives.push(0);
        }
    }
    let rs = [];
    let minInvoke = Number.MAX_VALUE;
    for (let k = 0; k < actives.length; k++) {
        if (actives[k] < minInvoke) {
            minInvoke = actives[k];
            rs = [];
            rs.push(servers[k]);
        } else if (actives[k] === minInvoke) {
            rs.push(servers[k]);
        }
    }
    const index = Math.floor(Math.random() * rs.length);
    const serverId = rs[index];
    client.laParam[serverType][serverId] += 1;
    utils.invokeCallback(cb, null, serverId);
}
function laRoute(client, serverType, msg, cb) {
    const servers = client._station.serversMap[serverType];
    if (!servers || !servers.length) {
        utils.invokeCallback(cb, new Error(`rpc servers not exist with serverType: ${serverType}`));
        return;
    }
    const actives = [];
    if (!client.laParam) {
        client.laParam = {};
    }
    if (client.laParam[serverType]) {
        for (let j = 0; j < servers.length; j++) {
            let count = client.laParam[serverType][servers[j]];
            if (!count) {
                count = 0;
                client.laParam[servers[j]] = 0;
            }
            actives.push(count);
        }
    } else {
        client.laParam[serverType] = {};
        for (let i = 0; i < servers.length; i++) {
            client.laParam[serverType][servers[i]] = 0;
            actives.push(0);
        }
    }
    let rs = [];
    let minInvoke = Number.MAX_VALUE;
    for (let k = 0; k < actives.length; k++) {
        if (actives[k] < minInvoke) {
            minInvoke = actives[k];
            rs = [];
            rs.push(servers[k]);
        } else if (actives[k] === minInvoke) {
            rs.push(servers[k]);
        }
    }
    const index = Math.floor(Math.random() * rs.length);
    const serverId = rs[index];
    client.laParam[serverType][serverId] += 1;
    utils.invokeCallback(cb, null, serverId);
}
function laRoute ( client , serverType , msg , cb ) { const servers = client . _station . serversMap [ serverType ] ; if ( ! servers || ! servers . length ) { utils . invokeCallback ( cb , new Error ( ` ${ serverType } ` ) ) ; return ; } const actives = [ ] ; if ( ! client . laParam ) { client . laParam = { } ; } if ( client . laParam [ serverType ] ) { for ( let j = 0 ; j < servers . length ; j ++ ) { let count = client . laParam [ serverType ] [ servers [ j ] ] ; if ( ! count ) { count = 0 ; client . laParam [ servers [ j ] ] = 0 ; } actives . push ( count ) ; } } else { client . laParam [ serverType ] = { } ; for ( let i = 0 ; i < servers . length ; i ++ ) { client . laParam [ serverType ] [ servers [ i ] ] = 0 ; actives . push ( 0 ) ; } } let rs = [ ] ; let minInvoke = Number . MAX_VALUE ; for ( let k = 0 ; k < actives . length ; k ++ ) { if ( actives [ k ] < minInvoke ) { minInvoke = actives [ k ] ; rs = [ ] ; rs . push ( servers [ k ] ) ; } else if ( actives [ k ] === minInvoke ) { rs . push ( servers [ k ] ) ; } } const index = Math . floor ( Math . random ( ) * rs . length ) ; const serverId = rs [ index ] ; client . laParam [ serverType ] [ serverId ] += 1 ; utils . invokeCallback ( cb , null , serverId ) ; }
Least-Active algorithm for calculating server id.

@param client {Object} rpc client.
@param serverType {String} rpc target serverType.
@param msg {Object} rpc message.
@param cb {Function} cb(err, serverId).
Least - Active algorithm for calculating server id .