Forum Discussion

mwarrior_268898's avatar
mwarrior_268898
Icon for Nimbostratus rankNimbostratus
Feb 15, 2017

Incorrect balancing using two pools based on cookies.

sorry colleagues, the description was cutted.

 

The problem is in incorrect balancing within two server pools. It works fine for 1 pool and goes unpredictabe for another. We have have two rules, 1 - defined pool 2 - check cookie and insert persistant record for server - cookie pair.

 

It works fine untill we've switch off one of the servers from the second pool. If so - all sessions comes to one server of the pilot pool, instead of balancing over 6 others virtual severs. I've put the existing rule in Preformatted code.

 

Maybe there are some predefine patterns and best practice for iRules we can use for that configuration ?

 

WBR, Dmitry.

 

when HTTP_REQUEST 
{
set need_cookie 0
set pinned_to_pilot 0
set pilot_region 0
set remove_bIPs_cookie 0
set do_not_persist 0

if { [HTTP::cookie exists "bIPs"] } 
{
         LB::detach
}
if { [HTTP::cookie exists "bIPs"] } 

{
set cookie_bIPs [HTTP::cookie value "bIPs"]
switch -- $cookie_bIPs
     {
       "564844779" { 
         set pinned_to_pilot 1
      }
       "-538018688" { 
         set pinned_to_pilot 1
        }
       "-1461105642"{ 
         set pinned_to_pilot 1
        }
       "836771244"{ 
         set pinned_to_pilot 1
        }
       "1189555514"{ 
         set pinned_to_pilot 1
        }
       "-662456167"{ 
         set pinned_to_pilot 1
        }
       "-1350268913" { 
         set pinned_to_pilot 1
        }
     }
   }
if { [HTTP::cookie exists "MVID_CITY_ID"] } 

 {
     set cookie_local [HTTP::cookie value "MVID_CITY_ID"]
     if { [class match $cookie_local equals ATG_PILOT_COOKIE_GROUP] } 
        {
          set pilot_region 1
        }
   }

set bIPs_crc_num ""
if {[HTTP::query] contains "o.bIPs"}
  {
      set bIPs_crc_num [URI::query [HTTP::uri] "o.bIPs"]
  }

switch -glob [HTTP::host]
  {

    "*mvl.ru" 
      {
        set domain "[www.mvl.ru"](//www.mvl.ru);
      } 
  }

if 
   { 
        not ([HTTP::path] starts_with "/assets/") 
    and not ([HTTP::path] starts_with "/media/")
    and not ([HTTP::path] starts_with "/errors/holdingPage.html")
    and not ([HTTP::path] starts_with "/sitemap.xml")
    and not ([HTTP::path] starts_with "/robots.txt")
    and not ([HTTP::path] starts_with "/sitemaps")
    and not ([HTTP::path] starts_with "/affiliates_unloads/")
    and not ([HTTP::path] starts_with "/favicon.ico") 
    } 
{
    if { ([HTTP::cookie value "bIPs"] ne "") }
    {
      if { not ($pinned_to_pilot) and not ($pilot_region) } 
       {
        persist uie [HTTP::cookie value "bIPs"]
        set need_cookie 0
       }
      elseif { ($pinned_to_pilot) and ($pilot_region) } 
       {
        persist uie [HTTP::cookie value "bIPs"]
        set need_cookie 0
       }
      else 
      { 
        set need_cookie 1
        set do_not_persist 1
      }
    } 
    else 
    {
        set need_cookie 1
    }

    if { ($bIPs_crc_num ne "") } 
    {
        persist uie [HTTP::cookie value "bIPs"]
    }
    `

    }
    }

    when LB_SELECTED 
    {
       if { 
            not ([HTTP::path] starts_with "/assets/") 
        and not ([HTTP::path] starts_with "/media/")
        and not ([HTTP::path] starts_with "/errors/holdingPage.html")
        and not ([HTTP::path] starts_with "/sitemap.xml")
        and not ([HTTP::path] starts_with "/robots.txt")
        and not ([HTTP::path] starts_with "/sitemaps")
        and not ([HTTP::path] starts_with "/affiliates_unloads/")
        and not ([HTTP::path] starts_with "/favicon.ico") 
          } 
        {

    
`if { ([HTTP::cookie value "bIPs"] ne "") and not ($do_not_persist)  } 
      {
         persist uie [HTTP::cookie value "bIPs"]
      }
    }

set do_not_persist 0
}

when PERSIST_DOWN 
{
    set need_cookie 1
    set do_not_persist 1
}

when HTTP_RESPONSE 
{
   set pool_is_dynamic 0
  if { ([LB::server pool] ==  "/Common/atg-ps-prod_tcp80") or ([LB::server pool] ==  "/Common/atg-pilot-pool")} 
   {
      set pool_is_dynamic 1 

      HTTP::cookie insert name "bIPs" value [crc32 [IP::server_addr]] path "/" domain $domain version 1
      HTTP::cookie httponly bIPs enable 

   }
   if { ($need_cookie) and ($pool_is_dynamic) } 
   {
      catch { persist add uie [crc32 [IP::server_addr]] }
   }
}

2 Replies

  • A simple write up on what you are intending to do and what is failing would be helpful along with formatting of the code. Use "Pre-formatted Code"

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    It is not clear here how a pool is selected.