1.基于libevent事件处理机制
http://www.monkey.org/~provos/libevent/
./configure --prefix=/usr/local make sudo make install
2.memcached:http://memcached.org/
./configure --with-libevent=/usr/local make make install
3.memcache安装成功 输入memcached -h
memcached 1.4.7 -p <num> TCP port number to listen on (default: 11211) -U <num> UDP port number to listen on (default: 11211, 0 is off) -s <file> UNIX socket path to listen on (disables network support) -a <mask> access mask for UNIX socket, in octal (default: 0700) -l <addr> interface to listen on (default: INADDR_ANY, all addresses) <addr> may be specified as host:port. If you don't specify a port number, the value you specified with -p or -U is used. You may specify multiple addresses separated by comma or by using -l multiple times -d run as a daemon -r maximize core file limit -u <username> assume identity of <username> (only when run as root) -m <num> max memory to use for items in megabytes (default: 64 MB) -M return error on memory exhausted (rather than removing items) -c <num> max simultaneous connections (default: 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 verbose (print errors/warnings while in event loop) -vv very verbose (also print client commands/reponses) -vvv extremely verbose (also print internal state transitions) -h print this help and exit -i print memcached and libevent license -P <file> save PID in <file>, only used with -d option -f <factor> chunk size growth factor (default: 1.25) -n <bytes> minimum space allocated for 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> number of threads to use (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 Disable use of 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)
启动方式:
-d 以守护程序(daemon)方式运行
-u root 指定用户,如果当前为 root ,需要使用此参数指定用户
-P /tmp/a.pid 保存PID到指定文件
内存设置:
-m 1024 数据内存数量,不包含memcached本身占用,单位为 MB
-M 内存不够时禁止LRU,报错
-n 48 初始chunk=key+suffix+value+32结构体,默认48字节
-f 1.25 增长因子,默认1.25
-L 启用大内存页,可以降低内存浪费,改进性能
连接设置:
-l 127.0.0.1 监听的 IP 地址,本机可以不设置此参数
-p 11211 TCP端口,默认为11211,可以不设置
-U 11211 UDP端口,默认为11211,0为关闭
并发设置:
-c 1024 最大并发连接数,默认1024,最好是200
-t 4 线程数,默认4。由于memcached采用NIO,所以更多线程没有太多作用
-R 20 每个event连接最大并发数,默认20
-C 禁用CAS命令(可以禁止版本计数,减少开销)
例如:
/usr/local/bin/memcached -d -u root -m 1024 -p 11210 -l 192.168.1.34 -P /opt/memcached/pid/m11210.pid