Forum Discussion

Bala_02_152654's avatar
Bala_02_152654
Icon for Nimbostratus rankNimbostratus
Aug 20, 2014

irule for load balancing to particular pool member based on maximum number of http requests

I have a virtual server 192.168.1.1 and pool members are 10.10.10.1 and 10.10.10.2 The both pool members are basically serving a streaming media content. It listens on either http or any streaming media port.

 

The requirement is if the number of http request or connection to the virtual server is more than 500 or say 1000 , only then the traffic should be redirected to second pool member say 10.10.10.2.

 

Kindly please assist me for the same.

 

Thanks

 

6 Replies

  • Hello

     

    The scenario used is VE, and i m only looking at a simple irule which can be used to that the first 1000 connection is exceeded then only it should be redirected to the second pool member.

     

  • i m only looking at a simple irule which can be used to that the first 1000 connection is exceeded then only it should be redirected to the second pool member.

     

    you can count number of active connections using table command. it could be similar to this (you have to revise it because the example counts number of active connections for each client ip).

     

    v10.1 - The table Command - Examples by Spark (Limiting Connections To A VIP)

     

    https://devcentral.f5.com/articles/v101-the-table-command-examples

     

    to send traffic to specific pool member, you can use pool or node command.

     

    pool

     

    https://devcentral.f5.com/wiki/iRules.pool.ashx

     

    node

     

    https://devcentral.f5.com/wiki/iRules.node.ashx

     

  • I would request if you can publish the exact irule with the syntax so that i can test the same.

     

    The requirement is for the first 1000 HTTP Get requests, the virtual server should load balance the traffic to the first pool member 10.10.10.1 and if the traffic exceed 1000, then it should load balance the same to the second pool member or node 10.10.10.2.

     

    Again after 2000th connection, counter should be set to 0 and as usual the next 1000 should go to 10.10.10.1 and go to 10.10.10.2 once the request is more than 1000 requests

     

  • i do mathematics (divide and remainder) to select pool member based on number of requests. this is just an example and you may have to revise to suit your environment. please be noted that this logic won't be accurate if some of the pool member is down.

    e.g.

     config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 69
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
            200.200.200.111:80 {
                address 200.200.200.111
            }
        }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when RULE_INIT {
      set static::multiply 10
      set static::pool "foo"
      set static::command "members $static::pool"
      set static::number [eval $static::command]
    }
    when CLIENT_ACCEPTED {
      set lb_fails 0
    }
    when HTTP_REQUEST {
      set c [table incr counter]
      set m1 [expr { ( $c - 1 ) / $static::multiply }]
      set m2 [expr { $m1 % $static::number }]
      pool [LB::server pool] member [lindex [lindex [members -list [LB::server pool]] $m2] 0]
    }
    when HTTP_RESPONSE {
      log local0. "c=$c server=[IP::server_addr]"
    }
    when LB_FAILED {
      if { $lb_fails < [active_members [LB::server pool]] } {
        LB::mode rr
        LB::reselect pool [LB::server pool]
      } else {
        incr lb_fails
      }
    }
    }
    
     test (generating 21 http requests)
    
    [root@ve11a:Active:In Sync] config  tail -f /var/log/ltm
    Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=1 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=2 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=3 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=4 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=5 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=6 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=7 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=8 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=9 server=200.200.200.111
    Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=10 server=200.200.200.111
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=11 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=12 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=13 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=14 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=15 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=16 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=17 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=18 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=19 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=20 server=200.200.200.101
    Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=21 server=200.200.200.111
    
  • Hi,

     

    Thanks for this nitass - I can't seem to get it to work with more than 2 pool members as the LB::reselect only seems to fire once...

     

    Does this work with more than 2 pool members?

     

    Thanks