twitter / twemproxy

A fast, light-weight proxy for memcached and redis
Apache License 2.0
12.13k stars 2.06k forks source link

how twemproxy write to memcache server #507

Open haihq88 opened 7 years ago

haihq88 commented 7 years ago

I have following setting for PHP session

session_cached:
  listen: 127.0.0.1:22123
  hash: fnv1a_64
  distribution: ketama
  timeout: 400
  backlog: 1024
  preconnect: true
  auto_eject_hosts: true
  server_retry_timeout: 2000
  server_failure_limit: 3
  servers:
    - 10.16.223.249:11211:1 b1
    - 10.16.223.254:11211:1 b2
    - 10.16.223.221:11211:1 b3
    - 10.16.223.204:11211:1 b4

When session created, how does it write to each memcache server? As i know, twemproxy is consistent hashing. Can we define number of memcache server will be written? for example, memcache has option memcache.session_redundancy=N

haihq88 commented 7 years ago

How Can i configure to store Session ID to 2 memcached servers in a pool? Currently, it stores only one memcache server.

charsyam commented 7 years ago

@haihq88 how many items do you put in? how about add more than 1000 items :)

haihq88 commented 7 years ago

I do not have 1000 items for now :) But i want to have failover incase one memcached server is down, clients session will not be lost.

charsyam commented 7 years ago

@haihq88 because it is hash, so in small numbers of items, it shows like your situation. It looks like throwing dice.

haihq88 commented 7 years ago

@charsyam Do you mean when i have many numbers of Session ID, it will stores to more than 1 memcached server?

charsyam commented 7 years ago

@haihq88 Yes. It will be distributed on your servers fairly

haihq88 commented 7 years ago

@charsyam Maybe you're misunderstanding me :) I mean, i want one key will store to more than 1 memcache servers. For example, my PHPSSEID=jhlni15gpp7c5dd7q3tht410l3; I want it stores to b1 and b2. Or maybe all of 4 memcached servers In case b1 is down. Twemproxy still can read it from b2 and client session will not be lost.

charsyam commented 7 years ago

@haihq88 No. only one node just will store it. so If one node is down, you will lost some datas.

hjhart commented 7 years ago

@haihq88: @charsyam is correct. Twemproxy is not meant as a redundant data store. You may want to look into some sort of application level session redundancy.

For example: https://www.digitalocean.com/community/tutorials/how-to-share-php-sessions-on-multiple-memcached-servers-on-ubuntu-14-04