Welcome! Log In Create A New Profile

Advanced

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh
April 20, 2011 12:12AM
On Wed, Apr 20, 2011 at 10:09 AM, Andy <nginx-forum@nginx.us> wrote:
> agentzh Wrote:
> -------------------------------------------------------
>> > And if it's Django, how do i make sure that
>> given the same key, both
>> > Django and Nginx will hash to the same memcached
>> server?
>> >
>>
>> If you want your python app to access memcached as
>> well, the
>> recommended approach is to pass the nginx variable
>> holding the hashed
>> memcached upstream name back to your fastcgi app.
>>
>
> How do I pass the nginx variable holding the hashed memcached upstream?
> Which variable is that?
>

Here's a complete nginx.conf example for this:

http {
upstream A {
server 10.32.110.5:11211;
}
upstream B {
server 10.32.110.16:11211;
}
upstream C {
server 10.32.110.27:11211;
}

upstream_list my_cluster A B C;

server {
location = /memc {
internal;
set $memc_key $query_string;
set $memc_exptime 3600; # cache one hour

# hashing the $memc_key to an upstream backend
# in the my_cluster upstream list, and set $backend:
set_hashed_upstream $backend my_cluster $memc_key;

# pass $backend to memc_pass:
memc_pass $backend;
}

location /myapp {
set $key 'my page key'; # you may want to construct a
dynamic cache key here...

set_hashed_upstream $backend my_cluster $key;

srcache_fetch GET /memc $key;
srcache_store PUT /memc $key;

fastcgi_param MEMC_BACKEND $backend;
fastcgi_pass unix:/path/to/your/python/app.sock;
}
}
}

Another way is to use Lua to pick up a memcached backend from your
memcached cluster, such that you can define your own hashing
algorithm, including your custom consistent hashing ones.

Here we use fastcgi_param to pass nginx variable $backend to your
fastcgi app such that your fastcgi app can read that from its
environment MEMC_BACKEND. Another approach is to append the $backend
value to the query string of the forwarded http request.

Cheers,
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to make Nginx work with distributed/multiple memcached servers?

Andy April 15, 2011 02:09PM

Re: How to make Nginx work with distributed/multiple memcached servers?

Akins, Brian April 15, 2011 02:30PM

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh April 18, 2011 01:16AM

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh April 18, 2011 01:18AM

Re: How to make Nginx work with distributed/multiple memcached servers?

杨显功 April 18, 2011 01:56AM

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh April 18, 2011 02:24AM

Re: How to make Nginx work with distributed/multiple memcached servers?

杨显功 April 18, 2011 02:42AM

Re: How to make Nginx work with distributed/multiple memcached servers?

Andy April 19, 2011 10:09PM

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh April 20, 2011 12:12AM

Re: How to make Nginx work with distributed/multiple memcached servers?

agentzh April 20, 2011 12:16AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 167
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready