显示标签为“memcached”的博文。显示所有博文
显示标签为“memcached”的博文。显示所有博文

2012年11月21日星期三

Memcached一致性Hash实测

使用的客户端

spy memcached

环境

先启动4个memcached服务,然后向这4个memcached实例写入1w个数据,测试数据分布情况;再增加一个实例,在5个实例的情况下,读取1w条记录,计算实际命中率

代码

启用一致性hash很容易,代码如下:
List servers = new ArrayList();
servers.add(new InetSocketAddress("192.168.12.167", 33001));
servers.add(new InetSocketAddress("192.168.12.167", 33002));
servers.add(new InetSocketAddress("192.168.12.167", 33003));
servers.add(new InetSocketAddress("192.168.12.167", 33004));
servers.add(new InetSocketAddress("192.168.12.167", 33005));
memCachedClient = new MemcachedClient(new KetamaConnectionFactory(), servers);

写入的分布比例


server1 2304
server2 2603
server3 2513
server4 2588

加入一个实例后的命中率

81.38%

2012年6月8日星期五

memcached启动参数


-p <num>     指定监听的TCP端口号,默认是11211
-U <num>     指定监听的TCP端口号 (默认: 11211, 0 表示关闭)
-s <file>     UNIX socket path to listen on (disables network support)
-a <mask>     access mask for UNIX socket, in octal (default: 0700)
-l <addr>    指定绑定的IP地址,多个地址用逗号分隔。
-d            以后台进程运行
-r            maximize core file limit
-u <username> 指定运行的帐号(只有root时有效)
-m <num>      最大内存使用值,单位是M(default: 64 MB)
-M            return error on memory exhausted (rather than removing items)
-c <num>      最大并发连接数 (默认: 1024)
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u <username> user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            日志模式 (在事件循环中打印错误/警告)
-vv           强日志模式 (还打印客户端的命令/响应)
-vvv        最大日志模式 (打印内部状态交互信息)
-h            打印帮助信息
-i            打印 memcached 和 libevent 的版权信息
-P <file>     -d参数下,指定pid file
-f <factor>   chunk size growth factor (default: 1.25)
-n <bytes>    为 key+value+flags  分配的最小空间(字节)(default: 48)
-L            Try to use large memory pages (if available). Increasing
              the memory page size could reduce the number of TLB misses
              and improve the performance. In order to get large pages
              from the OS, memcached will allocate the total item-cache
              in one large chunk.
-D <char>     Use <char> as the delimiter between key prefixes and IDs.
              This is used for per-prefix stats reporting. The default is
              ":" (colon). If this option is specified, stats collection
              is turned on automatically; if not, then it may be turned on
              by sending the "stats detail on" command to the server.
-t <num>      线程数 (default: 4)
-R            Maximum number of requests per event, limits the number of
              requests process for a given connection to prevent
              starvation (default: 20)
-C          禁用 CAS
-b            Set the backlog queue limit (default: 1024)
-B            Binding protocol - one of ascii, binary, or auto (default)
-I            Override the size of each slab page. Adjusts max item size
              (default: 1mb, min: 1k, max: 128m)
-o            Comma separated list of extended or experimental options
              - (EXPERIMENTAL) maxconns_fast: immediately close new
                connections if over maxconns limit
              - hashpower: An integer multiplier for how large the hash
                table should be. Can be grown at runtime if not big enough.
                Set this based on "STAT hash_power_level" before a
                restart.