FAQ

Page Discussion History

Difference between revisions of "HttpSplitClientsModule"

(References: Added link to the original documentation)
m (Murmurhash to Murmurhash2)
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
ngx_http_split_clients_module is used to split clients based on some conditions(e.g ip addresses, headers, cookies, etc).
 
ngx_http_split_clients_module is used to split clients based on some conditions(e.g ip addresses, headers, cookies, etc).
  
Example configuration:
+
= Examples =
 +
 
 +
== Basic configuration: ==
 
<geshi lang="nginx">
 
<geshi lang="nginx">
 
http {
 
http {
 
     split_clients "${remote_addr}AAA" $variant {
 
     split_clients "${remote_addr}AAA" $variant {
         0.5% .one;
+
         40.5% ".one";
         2.0% .two;
+
         59.5% ".two";
        - "";
+
 
     }
 
     }
  
Line 15: Line 16:
 
         location / {
 
         location / {
 
             index index${variant}.html;
 
             index index${variant}.html;
 +
        [...]
 +
    }
 
</geshi>
 
</geshi>
  
$cookie_..., etc, may be used as a source for splitting. The source string is hashed using MurmurHash2 (as of 1.0.1; previously CRC32) and the percent of the hash is used as source value.
+
On the example configuration above, the input for calculating the percentage is the variable plus string ('''"${remote_addr}AAA"'''). This string will be converted into a percentage value using ''MurmurHash2'', the result will be compared to the directives and fill the $variant variable with the value just after the percentage in the configuration directives.
  
= Directives =
+
Instead of '''${remote_addr}''', one could use '''${cookie}''', '''${args}''' or another [http://wiki.nginx.org/HttpCoreModule#Variables, nginx variable]. You may also add a salt (arbitrary string) if needed.
  
== split_clients ==
+
* Keep in mind that if you use a variable like '''${remote_addr}''' (user IP), the hash (and percentage) will always be the same as long as the user/client keep the same IP. In other words, the '''$variant''' value will always be the same for the same IP.
'''syntax:''' ''split_clients  $variable { ... } ''
+
* Hashing algorithm is MurmurHash2 since version 1.0.1; Previously CRC32.
  
'''default:''' ''none''
+
== Sending a query string variable to 51% of clients (to PHP scripts) ==
 +
<geshi lang="nginx">
 +
http {
 +
    split_clients "${remote_addr}" $additionalQsVariable {
 +
    51% "coolVariable=1";
 +
    49% "";
 +
}
  
'''context:''' ''http''
+
    server {
 +
        location ~ \.php$ {
 +
            set $args "${query_string}&${$additionalQsVariable}";
 +
            [...]
 +
        }
 +
    }
 +
</geshi>
 +
 
 +
= Directives =
 +
 
 +
== split_clients ==
 +
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/http/ngx_http_split_clients_module/split_clients.txt" />
  
 
= References =
 
= References =

Revision as of 17:54, 23 November 2012

Contents

Synopsis

ngx_http_split_clients_module is used to split clients based on some conditions(e.g ip addresses, headers, cookies, etc).

Examples

Basic configuration:

http {
    split_clients "${remote_addr}AAA" $variant {
        40.5% ".one";
        59.5% ".two";
    }
 
    server {
        location / {
             index index${variant}.html;
        [...]
    }

On the example configuration above, the input for calculating the percentage is the variable plus string ("${remote_addr}AAA"). This string will be converted into a percentage value using MurmurHash2, the result will be compared to the directives and fill the $variant variable with the value just after the percentage in the configuration directives.

Instead of ${remote_addr}, one could use ${cookie}, ${args} or another nginx variable. You may also add a salt (arbitrary string) if needed.

  • Keep in mind that if you use a variable like ${remote_addr} (user IP), the hash (and percentage) will always be the same as long as the user/client keep the same IP. In other words, the $variant value will always be the same for the same IP.
  • Hashing algorithm is MurmurHash2 since version 1.0.1; Previously CRC32.

Sending a query string variable to 51% of clients (to PHP scripts)

http {
    split_clients "${remote_addr}" $additionalQsVariable {
	    51% "coolVariable=1";
	    49% "";
	}
 
    server {
        location ~ \.php$ {
            set $args "${query_string}&${$additionalQsVariable}";
            [...]
        }
    }

Directives

split_clients

Syntax: split_clients string $variable { ... }
Default:
Context: http
Reference:split_clients


References