Forum Discussion

Kevin_106976's avatar
Kevin_106976
Icon for Nimbostratus rankNimbostratus
Jul 16, 2010

Distribute load based on uri

Hi,

 

 

I want to distribute load across two uri's (/some/uri1 and /some/uri2) on a 70/30 percentage basis. Can I do this via an iRule ?

 

15 Replies

  • Here is another one

     

     

    
     when RULE_INIT { 
        set counter 0 
     } 
     when HTTP_REQUEST { 
         if {$::counter <= 7} { 
          The first 7 requests are redirected to  URI 1 
           HTTP::redirect "http://uri1" 
           incr $::counter 
        } elseif {$::counter <= 10 } { 
           The next 3 requests are redirect to URI 2 
           HTTP::redirect "http://uri2" 
           incr $::counter 
        } else { 
          Reset counter and send the 11th request to URI 1 
          set $::counter 0 
           HTTP::redirect "http://uri1" 
        } 
     }   
     

     

     

    Again this is all untested conceptual irule code

     

     

    Bhattman

     

  • I think Bhattman's example would work. But the downside to using a global counter is that it will prevent the VS from being "load balanced" across all of the TMM cores or CPUs (if you're on a CMP capable platform and LTM version). Another poster, Kev, came up with a simple solution for scenarios like this:

     http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/aff/5/afv/topic/aft/1172658/afc/1196453/Default.aspx
    
    when HTTP_REQUEST { 
       if { rand() > 0.02 } { 
          pool default-pool 
       } else { 
          pool marketing-pool 
       } 
    } 
    

    You could adapt this to your scenario:

     http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/aff/5/afv/topic/aft/1172658/afc/1196453/Default.aspx
    
    when HTTP_REQUEST {
    
        Check if URI is one we want to redirect
       if {[HTTP::uri] contains "search"}{
    
          if { rand() > 0.70 } {
             HTTP::redirect "http://uri1"
          } else { 
             HTTP::redirect "http://uri2"
          } 
       } 
    }
    

    Aaron
  • Out of curiosity, anything wrong with sending traffic to a pool with 7:3 ratio and then choosing our redirect based on IP:addr [server_addr] ?
  • Spark suggested something similar a while back:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=812734&ptarget=812767

     

     

    But I think Kev's method is even simpler and more efficient.

     

     

    Aaron
  • Wow, I like those suggestions a lot. The one about using the random function is simply brilliant ! Thanks guys, I will try it out soon.