二、memcache 启动参数详解
memcache启动参数:(以最新1.6.17为例)
memcache --help命令提示
点击查看代码
memcached 1.6.17
-p, --port=<num> 小写p,memcached监听的tcp端口。(默认端口为11211)
-U, --udp-port=<num> 大写U memcached监听的UDP端口值,(默认端口为0, 关闭)(老版1.4默认开11211)
-s, --unix-socket=<file> 小写S。unix socket监听的socket路径。进程间通信(关闭网络支持)
-a, --unix-mask=<mask> 小写A。unix socket的权限位信息(访问掩码, 八进制) (默认: 700)
-A, --enable-shutdown 大写A。允许客户端使用shutdown命令。默认是不允许的。该选项将允许客户端的shutdown命令关闭memcached
-l, --listen=<addr> 小写L。memcached绑定的ip地址。如果不设置这个选项,那么memcached将使用INADDR_ANY。如果想指定多个IP地址,那么该选项的参数可以由多个ip组成,ip之间用逗号分隔。也可以多次使用这个选项,此时端口应该尾随ip而不是单独用-p选项指定。例如-l 127.0.0.1:8888,192.168.1.112:9999 或者 -l 127.0.0.1:8888 -l 192.168.1.112:9999
-d, --daemon 以守护进程的形式运行Memcached
-r, --enable-coredumps 将core文件大小设置为不受限制
-u, --user=<user> 小写u。当以root用户启动memcached的时候需要指定memcached的所属用户,其他用户启动memcached不需要此选项
-m, --memory-limit=<num> 小写m。memcached能够使用的最大内存值,默认是64MB。参数单位为MB。
-M, --disable-evictions 大写M。内存用尽时报错,而不是淘汰数据。(默认情况下,当memcached的内存使用完后,将进行LRU机制淘汰item以腾出空间。如果使用本选项那么将关闭LRU功能。当然关闭LRU不代表不能存储新数据。如果memcached里面存有过期失效的item,那么就可以存储新数据。否则将无法存储。)
-c, --conn-limit=<num> 小写c。最多允许多少个客户端同时在线(这个值不等价于listen函数的第二个参数),该选项和后面的b选项有所不同。 默认值为1024个
-k, --lock-memory 小写k。将memcached使用到的内存锁定在内存中,不准OS把memcached的内存移动到虚拟内存。因为当OS把memcached的内存移动到虚拟内存可能会导致页错误,降低memcached的响应时间
-v, --verbose 小写v。输出memcached运行时的错误和警告日志。-v -vv -vvv输出的信息依次增加。
-vv very verbose (also print client commands/responses)
-vvv extremely verbose (internal state transitions)
-h, --help print this help and exit
-i, --license 显示memcached和libevent的版权信息
-V, --version print version and exit
-P, --pidfile=<file> 大写p。该选项的参数指明memcached的pid保存文件。要和-d选项配合使用。注意运行的用户是否有权限写对应的文件
-f, --slab-growth-factor=<num> item的扩容因子。默认值为1.25。该选项的参数值可以是小数但必须大于1.0
-n, --slab-min-size=<bytes> 设置最小的item能存储多少字节的数据。
-L, --enable-largepages 如果OS允许的话,那么向OS申请更大的内存页。OS的默认内存页为4KB。大的内存页可以有效降低页表的大小,提高效率。此选项会使得memcached预先先OS全部所需的申请内存。当然这些内存尽量是用大内存页分配的
-D <char> 指定key前缀和ID的分隔符。用于stats报告状态信息,默认的分隔符为冒号":"。指定该选项会自动打开报告收集。也可以在启动memcached后,客户端使用stats detail on命令开启,。
-t, --threads=<num> 该选项的参数用于指定worker线程的个数,不建议超过64个。如果不设置该选项默认有4个线程
-R, --max-reqs-per-event worker线程连续为某个客户端执行命令的最大命令数。控制这个每个连接的请求数,可避免阻塞(默认20)
-C, --disable-cas 大写C。memcached默认是使用CAS的,本选项是禁用CAS
-b, --listen-backlog=<num> listen函数的第二个参数。该选项的参数赋值给settings.backlog。如果不设置该选项,那么默认为1024。该选项和前面的c选项有所不同
-B, --protocol=<name> memcached支持文本协议和二进制协议。该选项的参数用于指定使用的协议。默认情况下是根据客户端的命令而自动判断(也叫协商),参数只能取auto、binary、ascii这三个字符串值。
-I, --max-item-size=<num> 大写i。slab分配器中,每一个页的大小。这个选项的参数是一个数值表示页的大小。默认单位是B也可以在数值后面带K或者M(大小写都行),表示KB和MB。页的大小小于1KB或者大于128MB都是不允许的。不推荐使用该选项。
-F, --disable-flush-all 禁止客户端的flush_all命令。默认是允许客户端的flush_all命令的
-X, --disable-dumping 禁用 stats cachedump 和 lru_crawler metadump
-W --disable-watch 禁用watch 命令
-Y, --auth-file=<file> (实验)使用ascii协议进行认证。 格式 用户名:密码\n 用户:密码
-e, --memory-file=<file> (实验)指定文件来映射内存,只有在ram磁盘或者持久内存映射中使用。使缓存支持可重启
-o, --extended 逗号分割的扩展参数,大部分参数可以加上’no_’前缀来关闭
- maxconns_fast: 如果连接数超过了最大同时在线数(由-c选项指定),立即关闭新连接上的客户端
- hashpower: 哈希表的长度是2^n。这个值就是n的初始值。可以在启动memcached的时候通过-o hashpower设置。 设置的值要在[12, 64]之间。如果不设置,该值为0。哈希表的幂将取默认值16 (HASHPOWER_DEFAULT = 16)
set based on "STAT hash_power_level"
- tail_repair_time: 用于检测是否有item被已死线程所引用。一般不会出现这种情况,所以默认不开启这种检测。如果需要开启这种检测,那么需要使用本选项。本选项需要一个参数,参数值必须不小于10。
disabled by default; very dangerous option.
- hash_algorithm: 用于指定哈希算法。该选项必须带有参数。并且参数只能是字符串jenkins或者murmur3 options: jenkins, murmur3, xxh3
- no_lru_crawler: 禁用LRU爬虫线程。该选项不需要参数。
- lru_crawler_sleep: LRU爬虫线程工作时的休眠间隔。本选项需要一个参数作为休眠时间,单位为微秒,取值范围是[0, 1000000]。
- lru_crawler_tocrawl: LRU爬虫检查每条LRU队列中的多少个item。该选项带有一个参数。
- read_buf_mem_limit: 每个连接读写的缓冲大小,单位mb。除非连接非常多(2w+),不然 不要调整。默认为0, 不限制大小。
- no_lru_maintainer: 关闭新的 LRU系统和后台线程 (改进的分段LRU算法(Segmented LRU))
- hot_lru_pct: LRU热数据的比例,默认20. 需要开启lru_maintainer
- warm_lru_pct: LRU暖数据的比例,默认40. 需要开启lru_maintainer
- hot_max_factor: HOT 队列 tail age 大于 COLD 队列 tail age *该值
- warm_max_factor: WARM 队列 tail age 大于 COLD 队列 tail age *该值
- temporary_ttl: 小于该值的 item 进入 TEMP LRU,且除非 item 过期或删除,否则不会离开该队列,不会被剔除
- idle_timeout: 空闲线程的超时主动断开时间。默认是0, 不会超时(1.4.27)
- slab_chunk_max: 最大的slab 的 chunk大小。默认512K
- watcher_logbuf_size: watch命令启用流式日志时,日志的上限。提高可以避免日志满了丢失
- worker_logbuf_size: 每个worker的log输出限制,被后台线程读取,并写到watchers
- track_sizes: 显示每个slab 所用的大小。 这样可以直接用stats sizes命令去看分配 的数据大小(不然要用stats sizes_enable 来打开)
- no_hashexpand: 禁止hash扩容(危险)
- modern: 已经打开了的特性,以后会设置成默认
- no_modern: 使用老版的特性。用于禁用 slab_reassign、slab_automove、lru_crawler、 lru_maintainer、maxconns_fast 命令的别名。No modern 还将 hash_algorithm 设置为 jenkins,并允许内联 ASCII VALUE。适用于 memcached 1.5 版和更高版本。要还原为 modern(目前是默认值),您必须重新启动。
- External storage 外部存储相关参数 (see: https://memcached.org/extstore)
- ext_path: 将数据存储至内存之外其他缓存介质。比如 -o ext_path=/path/to/a/datafile:5G
- ext_page_size: size in megabytes of storage pages. (default: 64)
- ext_wbuf_size: size in megabytes of page write buffers. (default: 4)
- ext_threads: number of IO threads to run. (default: 1)
- ext_item_size: store items larger than this (bytes, default 512)
- ext_item_age: store items idle at least this long (seconds, default: no age limit)
- ext_low_ttl: consider TTLs lower than this specially (default: 0)
- ext_drop_unread: don't re-write unread values during compaction (default: disabled)
- ext_recache_rate: recache an item every N accesses (default: 2000)
- ext_compact_under: compact when fewer than this many free pages
(default: 1/4th of the assigned storage)
- ext_drop_under: drop COLD items when fewer than this many free pages
(default: 1/4th of the assigned storage)
- ext_max_frag: max page fragmentation to tolerate (default: 0.80)
- ext_max_sleep: max sleep time of background threads in us (default: 1000000)
- slab_automove_freeratio: ratio of memory to hold free as buffer.
(see doc/storage.txt for more info, default: 0.010)
-N, --napi_ids number of napi ids. see doc/napi_ids.txt for more details
英文原版对照:
点击查看代码
memcached 1.6.17
-p, --port=<num> TCP port to listen on (default: 11211)
-U, --udp-port=<num> UDP port to listen on (default: 0, off)
-s, --unix-socket=<file> UNIX socket to listen on (disables network support)
-a, --unix-mask=<mask> access mask for UNIX socket, in octal (default: 700)
-A, --enable-shutdown enable ascii "shutdown" command
-l, --listen=<addr> interface to listen on (default: INADDR_ANY)
-d, --daemon run as a daemon
-r, --enable-coredumps maximize core file limit
-u, --user=<user> assume identity of <username> (only when run as root)
-m, --memory-limit=<num> item memory in megabytes (default: 64)
-M, --disable-evictions return error on memory exhausted instead of evicting
-c, --conn-limit=<num> max simultaneous connections (default: 1024)
-k, --lock-memory lock down all paged memory
-v, --verbose verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/responses)
-vvv extremely verbose (internal state transitions)
-h, --help print this help and exit
-i, --license print memcached and libevent license
-V, --version print version and exit
-P, --pidfile=<file> save PID in <file>, only used with -d option
-f, --slab-growth-factor=<num> chunk size growth factor (default: 1.25)
-n, --slab-min-size=<bytes> min space used for key+value+flags (default: 48)
-L, --enable-largepages try to use large memory pages (if available)
-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, --threads=<num> number of threads to use (default: 4)
-R, --max-reqs-per-event maximum number of requests per event, limits the
requests processed per connection to prevent
starvation (default: 20)
-C, --disable-cas disable use of CAS
-b, --listen-backlog=<num> set the backlog queue limit (default: 1024)
-B, --protocol=<name> protocol - one of ascii, binary, or auto (default: auto-negotiate)
-I, --max-item-size=<num> adjusts max item size
(default: 1m, min: 1k, max: 1024m)
-F, --disable-flush-all disable flush_all command
-X, --disable-dumping disable stats cachedump and lru_crawler metadump
-W --disable-watch disable watch commands (live logging)
-Y, --auth-file=<file> (EXPERIMENTAL) enable ASCII protocol authentication. format:
user:pass\nuser2:pass2\n
-e, --memory-file=<file> (EXPERIMENTAL) mmap a file for item memory.
use only in ram disks or persistent memory mounts!
enables restartable cache (stop with SIGUSR1)
-o, --extended comma separated list of extended options
most options have a 'no_' prefix to disable
- maxconns_fast: immediately close new connections after limit (default: enabled)
- hashpower: an integer multiplier for how large the hash
table should be. normally grows at runtime. (default starts at: 0)
set based on "STAT hash_power_level"
- tail_repair_time: time in seconds for how long to wait before
forcefully killing LRU tail item.
disabled by default; very dangerous option.
- hash_algorithm: the hash table algorithm
default is murmur3 hash. options: jenkins, murmur3, xxh3
- no_lru_crawler: disable 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)
- read_buf_mem_limit: limit in megabytes for connection read/response buffers.
do not adjust unless you have high (20k+) conn. limits.
0 means unlimited (default: 0)
- no_lru_maintainer: disable new LRU system + background thread.
- hot_lru_pct: pct of slab memory to reserve for hot lru.
(requires lru_maintainer, default pct: 20)
- warm_lru_pct: pct of slab memory to reserve for warm lru.
(requires lru_maintainer, default pct: 40)
- hot_max_factor: items idle > cold lru age * drop from hot lru. (default: 0.20)
- warm_max_factor: items idle > cold lru age * this drop from warm. (default: 2.00)
- temporary_ttl: TTL's below get separate LRU, can't be evicted.
(requires lru_maintainer, default: 61)
- idle_timeout: timeout for idle connections. (default: 0, no timeout)
- slab_chunk_max: (EXPERIMENTAL) maximum slab size in kilobytes. use extreme care. (default: 512)
- watcher_logbuf_size: size in kilobytes of per-watcher write buffer. (default: 256)
- worker_logbuf_size: size in kilobytes of per-worker-thread buffer
read by background thread, then written to watchers. (default: 64)
- track_sizes: enable dynamic reports for 'stats sizes' command.
- no_hashexpand: disables hash table expansion (dangerous)
- modern: enables options which will be default in future.
currently: nothing
- no_modern: uses defaults of previous major version (1.4.x)
- External storage (ext_*) related options (see: https://memcached.org/extstore)
- ext_path: file to write to for external storage.
ie: ext_path=/mnt/d1/extstore:1G
- ext_page_size: size in megabytes of storage pages. (default: 64)
- ext_wbuf_size: size in megabytes of page write buffers. (default: 4)
- ext_threads: number of IO threads to run. (default: 1)
- ext_item_size: store items larger than this (bytes, default 512)
- ext_item_age: store items idle at least this long (seconds, default: no age limit)
- ext_low_ttl: consider TTLs lower than this specially (default: 0)
- ext_drop_unread: don't re-write unread values during compaction (default: disabled)
- ext_recache_rate: recache an item every N accesses (default: 2000)
- ext_compact_under: compact when fewer than this many free pages
(default: 1/4th of the assigned storage)
- ext_drop_under: drop COLD items when fewer than this many free pages
(default: 1/4th of the assigned storage)
- ext_max_frag: max page fragmentation to tolerate (default: 0.80)
- ext_max_sleep: max sleep time of background threads in us (default: 1000000)
- slab_automove_freeratio: ratio of memory to hold free as buffer.
(see doc/storage.txt for more info, default: 0.010)
-N, --napi_ids number of napi ids. see doc/napi_ids.txt for more details
windows 版下载:
https://www.runoob.com/memcached/window-install-memcached.html
https://www.apachelounge.com/viewtopic.php?p=37578
https://github.com/nono303/memcached/
参考资料:
https://blog.csdn.net/luotuo44/article/details/42672913
https://docs.aws.amazon.com/zh_cn/AmazonElastiCache/latest/mem-ug/ParameterGroups.Memcached.html
https://cloud.google.com/memorystore/docs/memcached/memcached-configs
https://www.cnblogs.com/ELMND/p/4533838.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?