AB testing with nginx

Hello,
I need testing our web-site using AB Test.
One half request serve by first upstream, and other request serve by
second upstream.

But If request goes from same people/computer/IP is necessary route
request to same upstream like last request from this people/computer/IP.

I think that I may split user by IP adress. Even IP(last 3 digits from
IP) route to first upstream and odd IP route to second upstream.
But how to do that?

Thanks for help
Dawe

Posted at Nginx Forum:

Hello!

On Tue, Nov 03, 2009 at 04:27:13AM -0500, dawe7 wrote:

Hello,
I need testing our web-site using AB Test.
One half request serve by first upstream, and other request serve by second upstream.

But If request goes from same people/computer/IP is necessary route request to same upstream like last request from this people/computer/IP.

I think that I may split user by IP adress. Even IP(last 3 digits from IP) route to first upstream and odd IP route to second upstream.
But how to do that?

http://wiki.nginx.org/NginxHttpUpstreamModule#ip_hash

Maxim D.

Thanks, but here is one problem:

If I have 3 servers (or more) in upstream, I split traffic to 33%, 33%,
33%. No 50% and 50%.

And second problem is If I use servers with different performance. I may
overload one of this server.
Because I can not combine ip_hash and weight methods for connection
distribution and set one server weight=2 and others servers weight=1.
And split traffic to 50%,25%+25%.

Posted at Nginx Forum:

You can store experiment variants in a cookie and then chose one
upstream from several independent upstreams using the cookie value,
while having all servers configured in every upstream.

Hello!

On Tue, Nov 03, 2009 at 05:17:57AM -0500, dawe7 wrote:

Thanks, but here is one problem:

If I have 3 servers (or more) in upstream, I split traffic to 33%, 33%, 33%. No 50% and 50%.

And second problem is If I use servers with different performance. I may overload one of this server.
Because I can not combine ip_hash and weight methods for connection distribution and set one server weight=2 and others servers weight=1.
And split traffic to 50%,25%+25%.

Well, if you need more generic aproach you may rewrite requests
to another location and handle them differently. Try something
like this:

location / {
    if ($remote_addr ~ "[02468]$") {
        rewrite ^(.*) /test/$1 last;
    }

    proxy_pass http://normal_backend/;
}

location /test/ {
    internal;
    proxy_pass http://test_backend/;
}

Maxim D.