教程 memcached tutorial

使用 stats

Memcached 提供 stats 命令,输出服务器运行的详细统计信息,便于监控和调优。

常用 stats 类型

  • stats: 显示基本统计数据,如命中次数、存储项数、内存使用等。
  • stats settings: 显示当前服务器配置参数。
  • stats items: 显示缓存条目分布情况。
  • stats slabs: 显示内存分配细节。

示例

使用 telnet 连接 Memcached:

bash
telnet 127.0.0.1 11211
stats

`

返回示例:

bash
STAT pid 12345
STAT uptime 3600
STAT curr_items 1000
STAT total_items 5000
STAT bytes 1048576
STAT curr_connections 50
STAT cmd_get 20000
STAT get_hits 15000
STAT get_misses 5000
END

关键指标说明

  • get_hits 和 get_misses:缓存命中与未命中次数。
  • curr_items:当前缓存项数量。
  • bytes:当前使用的内存字节数。
  • curr_connections:当前连接数。
  • uptime:服务器运行时间(秒)。

运用

结合 stats 数据,可以分析缓存命中率、内存使用和连接负载,调整配置提升性能。