memcached的一些启动参数,举个例子:
memcached -p 11212 -d -u root
启动memcached的时候,这些-p,-d,-u参数。
从源码中看得出来,启动参数有下面这些:
-pTCP port number to listen on (default: 11211) --U UDP port number to listen on (default: 11211, 0 is off) --s UNIX socket path to listen on (disables network support) --A enable ascii \"shutdown\command --a access mask for UNIX socket, in octal (default: 0700) --l interface to listen on (default: INADDR_ANY, all addresses) 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 assume identity of (only when run as root) --m max memory to use for items in megabytes (default: 64 MB) --M return error on memory exhausted (rather than removing items) --c 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 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 --V print version and exit --P save PID in , only used with -d option --f chunk size growth factor (default: 1.25) --n 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 Use 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 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)); -S Turn on Sasl authentication); -F Disable flush_all command); -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. - tail_repair_time: Time in seconds that indicates how long to wait before forcefully taking over the LRU tail item whose refcount has leaked. Disabled by default; dangerous option. - hash_algorithm: The hash table algorithm default is jenkins hash. options: jenkins, murmur3 - lru_crawler: Enable LRU Crawler background thread - lru_crawler_sleep: Microseconds to sleep between items default is 100. - lru_crawler_tocrawl: Max items to crawl per slab per run default is 0 (unlimited) - lru_maintainer: Enable new LRU system + background thread - hot_lru_pct: Pct of slab memory to reserve for hot lru. (requires lru_maintainer) - warm_lru_pct: Pct of slab memory to reserve for warm lru. (requires lru_maintainer) - expirezero_does_not_evict: Items set to not expire, will not evict. (requires lru_maintainer)
以下是鄙人的翻译:
参数名 | 说明 | 重要性 | 特别说明 |
-p |
TCP监听端口(default: 11211) | 高 | |
-U |
UDP监听端口(default: 11211, 0 is off) | 低 | 广播,不太符合使用场景。 |
-s |
用于监听的UNIX套接字路径(禁用网络支持) |
低 | |
-A | nc/telnet 到memcached后,输入“shutdown”关闭memcached进程 | 低 | 如果线上可以外网访问,被别人这样子shutdown了。。。 |
-a |
UNIX套接字访问掩码,八进制数字(默认:0700) | 低 | |
-l |
监听哪一块网卡(default: INADDR_ANY, all addresses) | 低 | |
-d | 以守护进程的方式运行 | 高 | 一般memcached都是守护进程的。 |
-r | 最大核心文件限制。 | 低 | 较少使用 |
-u |
assume identity of |
中 | 设定进程所属用户。 root权限启动mc的时候一定要输入这个参数。 一般就是: -u root |
-m |
memcached的内存大小 (default: 64 MB) | 高 | 生产环境一般都改大,例如2G 4G。 |
-M | 内存耗尽的时候返回错误,而不是lru | 低 | 一般不用。 |
-c |
最大连接数 (default: 1024) | 中 | 较少设置这个参数。 要设置这个参数 不如多个MC实例跑一致性hash。 |
-k | lock down all paged memory. Note that there is a limit on how much memory you may lock. Trying to |
低 | 一般不动这个参数 |
-v -vv -vvv -h -i -V |
输出日志 print errors/warnings |
中 |
研发环境可以玩玩; 线上影响性能 |
-P |
-d的时候才会配套使用,输出pid文件 | 中 | 有点用 |
-f |
chunk大小的增长因子(default: 1.25) | 高 | 线上不一定使用; 但是这个参数对于理解memcached的内存模型很有意义, 对于memcached的内存利用率很大影响。 |
-n |
minimum space allocated for key+value+flags (default: 48) chunk的最小大小 |
高 | 与-f参数类似,对于理解memcached的内存模型很有意义, 对于内存利用率较大影响 |
-L | Try to use large memory pages (if available). Increasing |
高 | 比较影响性能 |
-D |
Use |
? | |
-t |
使用多少个线程 (default: 4) | 中 | |
-R | Maximum number of requests per event, limits the number of |
较少设置 | |
-C | 不允许CAS | 低 | 一般不用这个参数 |
-b | backlog队列大小(linux socket三次握手后,socket进入的队列大小) (default: 1024) |
中 | 可以研发环境玩玩。 线上出现要调整这个参数的时候, 不如增加memcached实例。 |
-B | 二进制协议(默认文本协议,1.4以前的MC只支持文本协议) one of ascii, binary, or auto (default) |
中 | 追求点性能可以用二进制协议。mc的客户端也要使用二进制。 |
-I | Override the size of each slab page. Adjusts max item size |
高 | 调优指令 |
-S | Turn on Sasl authentication |
中 | 需要安装mc的时候,configure命令中有enable-sasl 否则后面想开启Sasl的时候启动mc失败的,日志会显示: This server is not built with SASL support. |
-F | 不允许flush_all命令 | 中 | 看情况使用 |
-o | 逗号切割多个,实验参数 - (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. - tail_repair_time: Time in seconds that indicates how long to wait before forcefully taking over the LRU tail item whose refcount has leaked. Disabled by default; dangerous option. - hash_algorithm: The hash table algorithm default is jenkins hash. options: jenkins, murmur3 - lru_crawler: Enable LRU Crawler background thread - lru_crawler_sleep: Microseconds to sleep between items default is 100. - lru_crawler_tocrawl: Max items to crawl per slab per run default is 0 (unlimited) - lru_maintainer: Enable new LRU system + background thread - hot_lru_pct: Pct of slab memory to reserve for hot lru. (requires lru_maintainer) - warm_lru_pct: Pct of slab memory to reserve for warm lru. (requires lru_maintainer) - expirezero_does_not_evict: Items set to not expire, will not evict. (requires lru_maintainer) |
低 |
蓝色加粗的参数是我觉得比较重要/有用的参数。