注意

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

内存分析

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

sudo apt-get install google-perftools

分析器将输出保存到你的log file目录 (/var/log/ceph)。日志和调试 for details.

要使用 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} with mon, osdmds

  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

Note

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

导出堆信息

要导出堆信息,运行以下格式的命令:

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

例如:

ceph tell mds.a heap dump

Note

导出堆信息仅在分析器运行时有效。

释放内存

要释放 Ceph 守护进程本身已分配但未使用的内存,运行以下格式的命令:tcmalloc has allocated but which is not being used by the Ceph daemon itself, run a command of the following form:

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 文档 for more information.

从你的发行版的包管理器安装 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 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.