注意

本文档适用于 Ceph 的开发版本。

内存分析

Ceph Monitor、OSD 和 MDS 可以报告 TCMalloc 堆配置文件。如果您想生成这些配置文件,请安装 google-perftools。您的操作系统发行版可能将其打包为不同的名称(例如 gperftools),并且您的操作系统发行版可能使用不同的包管理器。运行类似于以下命令来安装 google-perftools

sudo apt-get install google-perftools

分析器将输出转储到您的 log file 目录 (/var/log/ceph)。有关详细信息,请参阅日志和调试

要使用 Google 的性能工具查看分析器日志,请运行以下命令

google-pprof --text {path-to-daemon}  {log-path/filename}

例如

$ ceph tell osd.0 heap start_profiler
$ ceph tell osd.0 heap dump
osd.0 tcmalloc heap stats:------------------------------------------------
MALLOC:        2632288 (    2.5 MiB) Bytes in use by application
MALLOC: +       499712 (    0.5 MiB) Bytes in page heap freelist
MALLOC: +       543800 (    0.5 MiB) Bytes in central cache freelist
MALLOC: +       327680 (    0.3 MiB) Bytes in transfer cache freelist
MALLOC: +      1239400 (    1.2 MiB) Bytes in thread cache freelists
MALLOC: +      1142936 (    1.1 MiB) Bytes in malloc metadata
MALLOC:   ------------
MALLOC: =      6385816 (    6.1 MiB) Actual memory used (physical + swap)
MALLOC: +            0 (    0.0 MiB) Bytes released to OS (aka unmapped)
MALLOC:   ------------
MALLOC: =      6385816 (    6.1 MiB) Virtual address space used
MALLOC:
MALLOC:            231              Spans in use
MALLOC:             56              Thread heaps in use
MALLOC:           8192              Tcmalloc page size
------------------------------------------------
Call ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).
Bytes released to the OS take up virtual address space but no physical memory.
$ google-pprof --text \
               /usr/bin/ceph-osd  \
               /var/log/ceph/ceph-osd.0.profile.0001.heap
 Total: 3.7 MB
 1.9  51.1%  51.1%      1.9  51.1% ceph::log::Log::create_entry
 1.8  47.3%  98.4%      1.8  47.3% std::string::_Rep::_S_create
 0.0   0.4%  98.9%      0.0   0.6% SimpleMessenger::add_accept_pipe
 0.0   0.4%  99.2%      0.0   0.6% decode_message
 ...

对同一守护程序执行另一次堆转储会创建另一个文件。将新文件与先前堆转储创建的文件进行比较很方便,可以显示在此期间增长了哪些内容。例如

$ google-pprof --text --base out/osd.0.profile.0001.heap \
      ceph-osd out/osd.0.profile.0003.heap
 Total: 0.2 MB
 0.1  50.3%  50.3%      0.1  50.3% ceph::log::Log::create_entry
 0.1  46.6%  96.8%      0.1  46.6% std::string::_Rep::_S_create
 0.0   0.9%  97.7%      0.0  26.1% ReplicatedPG::do_op
 0.0   0.8%  98.5%      0.0   0.8% __gnu_cxx::new_allocator::allocate

有关其他详细信息,请参阅Google 堆分析器

安装堆分析器后,启动集群并开始使用堆分析器。您可以在运行时启用或禁用堆分析器,或确保它持续运行。运行基于以下示例的命令时,请执行以下操作

  1. {daemon-type} 替换为 monosdmds

  2. {daemon-id} 替换为 OSD 编号、MON ID 或 MDS ID

启动分析器

要启动堆分析器,请运行以下形式的命令

ceph tell {daemon-type}.{daemon-id} heap start_profiler

例如

ceph tell osd.1 heap start_profiler

或者,如果在环境中找到 CEPH_HEAP_PROFILER_INIT=true 变量,则配置文件将在守护程序开始运行时启动。

打印统计信息

要打印统计信息,请运行以下形式的命令

ceph  tell {daemon-type}.{daemon-id} heap stats

例如

ceph tell osd.0 heap stats

注意

使用此命令报告统计信息不需要分析器正在运行,也不会将堆分配信息转储到文件中。

转储堆信息

要转储堆信息,请运行以下形式的命令

ceph tell {daemon-type}.{daemon-id} heap dump

例如

ceph tell mds.a heap dump

注意

转储堆信息仅在分析器运行时有效。

释放内存

要释放 tcmalloc 已分配但 Ceph 守护程序本身未使用的内存,请运行以下形式的命令

ceph tell {daemon-type}{daemon-id} heap release

例如

ceph tell osd.2 heap release

停止分析器

要停止堆分析器,请运行以下形式的命令

ceph tell {daemon-type}.{daemon-id} heap stop_profiler

例如

ceph tell osd.0 heap stop_profiler

内存分析的替代方法

使用 Valgrind 运行 Massif 堆分析器

Massif 堆分析器工具可与 Valgrind 一起使用来衡量使用了多少堆内存。此方法非常适合对 RadosGW 进行故障排除。

有关更多信息,请参阅 Massif 文档

从发行版的包管理器安装 Valgrind,然后启动要进行故障排除的 Ceph 守护程序

sudo -u ceph valgrind --max-threads=1024 --tool=massif /usr/bin/radosgw -f --cluster ceph --name NAME --setuser ceph --setgroup ceph

此命令运行完成后,将在当前工作目录中保存一个名为 massif.out.<pid> 的文件。要运行上述命令,运行它的用户必须对当前目录具有写入权限。

运行 ms_print 命令以从 massif.out.<pid> 文件中收集的数据中获取图表和统计信息

ms_print massif.out.12345

此命令的输出在提交错误报告时很有用。

由 Ceph 基金会为您呈现

Ceph 文档是由非营利性 Ceph 基金会 资助和托管的社区资源。如果您希望支持这项工作和我们的其他努力,请考虑 立即加入