ngx_http_upstream_memcached_hash_module
Skip to the end for download. Git repository: git clone git://openhack.ru/nginx-patched.git branch memcached_hash.
| syntax: memcached_hash [ketama_points=points] [weight_scale=weight] default: none context: upstream |
| syntax: set $memcached_namespace "string"; default: "" context: server, location, if |
This module implements memcached_hash directive for upstream blocks. The purpose of this directive is to direct nginx to the right memcached server, the one that would be used by Cache::Memcached::Fast (or its ancestor Cache::Memcached) for the same key. Thus you may upload the data to memcached cluster with the Perl script using C::M::F (or in general with any client that is compatible with C::M), and then serve that data with nginx.
Parameters of memcached_hash directive:
ketama_points=points - how many points the server has
weight_scale=scale - denominator by which ketama points and server weights are scaled down. Thus, if you have ketama_points=150 and weight_scale=10 the server gets 150/10 = 15 points.
The typical configuration will be
server {
location / {
set $memcached_key "$uri$is_args$args";
set $memcached_namespace "prefix";
memcached_pass memcached_cluster;
error_page 404 502 504 = @fallback;
}
location @fallback {
proxy_pass http://backend;
}
}
and memcached_cluster will be defined as
upstream memcached_cluster {
memcached_hash;
server localhost:11211 weight=2;
server 192.168.254.2:11211;
server unix:/path/to/unix.sock weight=4;
}
or
upstream memcached_cluster {
memcached_hash ketama_points=150 weight_scale=10;
server localhost:11211 weight=25;
server 192.168.254.2:11211 weight=10;
server unix:/path/to/unix.sock weight=40;
}
when corresponding parameters to Cache::Memcached::Fast are
my $memd = new Cache::Memcached::Fast({
servers => [ { address => 'localhost:11211', weight => 2 },
'192.168.254.2:11211',
{ address => '/path/to/unix.sock', weight => 4 } ],
namespace => 'prefix',
...
});
or
my $memd = new Cache::Memcached::Fast({
servers => [ { address => 'localhost:11211', weight => 2.5 },
'192.168.254.2:11211',
{ address => '/path/to/unix.sock', weight => 4 } ],
namespace => 'prefix',
ketama_points => 150,
...
});
respectively. See README for further details.
Back to nginx-patched.
Attachments
-
ngx_http_upstream_memcached_hash_module-0.01.tar.bz2
(7.5 KB) - added by tomash
2 years ago.
-
ngx_http_upstream_memcached_hash_module-0.02.tar.bz2
(8.7 KB) - added by tomash
2 years ago.
-
ngx_http_upstream_memcached_hash_module-0.03.tar.bz2
(8.8 KB) - added by tomash
22 months ago.
-
ngx_http_upstream_memcached_hash_module-0.04.tar.bz2
(9.1 KB) - added by tomash
12 months ago.
