[FreeNX-kNX] new load_balance_algorithm ?

Chris Fanning christopher.fanning at gmail.com
Fri May 16 08:46:19 UTC 2008


Hi,

I've been testing this out and it seems to work well.
One problem I did have is when the hosts in LOAD_BALANCE_SERVERS are
defined as IP's and not as names. So I just change the '.' to a '_'.

I understand that good loadbalancing is tricky, but, don't you think
that 'usercount' is better than 'random' and 'round-robin'?

Cheers.
Chris.

server_loadbalance_usercount()
{
        log 5 "Info: Load-Balancing per user-count"
        hosts_sessions=""
        for i in $NX_SESS_DIR/running/*
        do
                [ -f $i ] || break
                CMDLINE=$(session_get_cmdline $i)
                hosts_sessions=$hosts_sessions$(getparam host)" "
        done

        VAR="HOST"
        for host in ${hosts_sessions}
        do
                host_name=${host//./_}
                eval `echo $VAR$host_name`+=1
        done

        smallest_load=-1
        for host in ${LOAD_BALANCE_SERVERS}
        do
                host_name=${host//./_}
                varname=$VAR$host_name
                count=${!varname}
                log 5 "Info: host:$host  count:${#count}"
                if [ $smallest_load == -1 ]; then
                        smallest_load=${#count}
                        SERVER_LB_HOST=$host
                elif [ ${#count} -lt $smallest_load ]; then
                        smallest_load=${#count}
                        SERVER_LB_HOST=$host
                fi
        done
        echo $SERVER_LB_HOST
}


On Wed, May 14, 2008 at 5:54 PM, Chris Fanning
<christopher.fanning at gmail.com> wrote:
> Hi,
>
> I'd like to try to loadbalance by the number of running sessions on each node.
> The new session is opened on the node with the least connected users.
> Perhaps something like this.
>
> Any thoughts?
>
> server_loadbalance_usercount()
>        node_sessions=""
>        for i in $NX_SESS_DIR/running/*
>        do
>                [ -f $i ] || break
>                CMDLINE=$(session_get_cmdline $i)
>                node_sessions=$node_sessions$(getparam host)" "
>        done
>
>        VAR="NODE"
>        for node in ${node_sessions}
>        do
>                eval `echo $VAR$node`+=1
>        done
>
>        smallest_load=-1
>        for node in ${LOAD_BALANCE_SERVERS}
>        do
>                varname=$VAR$node
>                count=${!varname}
>                #echo "node: $node, count: ${#count}"
>                if [ $smallest_load == -1 ]; then
>                        smallest_load=${#count}
>                        SERVER_LB_HOST=$node
>                elif [ ${#count} -lt $smallest_load ]; then
>                        smallest_load=${#count}
>                        SERVER_LB_HOST=$node
>                fi
>        done
>        echo $SERVER_LB_HOST
> }
>



More information about the FreeNX-kNX mailing list