Brocade Stingray Traffic Manager with Traffic Script for random pool selection

I remember once I received a request to configure Stingray Traffic Manager to load balance traffic in proportion of 20% and 80% where 20% of incoming traffic should hit new development web servers in a new backend pool and 80% of incoming traffic should hit old production web servers.

The purpose for this was to test new developed code and overall user experience before switching to the new code release permanently.

This solution was tested on a site which has about 5K-10K visits daily.

The below is the Traffic Script code which you need to apply as rule for your Virtual Server.

#Get the REQUEST cookie ONCE
$cookie = http.getCookie("nfsec-cookie");

#If it's 0, use s1-web-pool-80
if ($cookie == "0") {  
    pool.use("nfsec-prod-pool-80");

#Or if it's 1, use s1-test-pool
} else if ($cookie == "1") {
    pool.use("nfsec-dev-pool-80");

#Otherwise the cookie is empty or invalid...
} else {

    #Set the Cookie
    $rand = math.random(10);
    if ($rand > 1) {
        http.setResponseCookie("nfsec-cookie", "0", "path=/; expires=Mon, 13 Feb 2018 23:59:59 GMT;");
        pool.use("nfsec-prod-pool-80");
    } else {
        http.setResponseCookie("nfsec-cookie", "1", "path=/; expires=Mon, 13 Feb 2018 23:59:59 GMT;");
        pool.use("nfsec-dev-pool-80");
    }
}

I hope this was useful for your new code release testing on a live platform allowing randomly selected users to test your new code :]

Share this post:

by lo3k