Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] RocksDB memory occupation out of control #2204

Closed
mchgood opened this issue Apr 27, 2023 · 8 comments
Closed

[Question] RocksDB memory occupation out of control #2204

mchgood opened this issue Apr 27, 2023 · 8 comments
Labels
improvement General improvement rocksdb RocksDB backend

Comments

@mchgood
Copy link

mchgood commented Apr 27, 2023

Problem Type (问题类型)

Your Question (问题描述)

目前我发现 java 服务内存占用过高的问题,看起来像是 rocksdb 堆外内存占用。详细信息如下:

  1. java jvm 配置
java -Xms1g -Xmx2g
  1. 缓存配置
vertex.cache_capacity=100000
vertex.cache_expire=3600
edge.cache_expire=3600
  1. top 命令查看内存占用
RES 占用3.2G

如果重启应用,内存会保持在2.4G左右,然后缓慢增长到3.2G。
通过查询 rocksdb 相关资料,找到如下 issue
facebook/rocksdb#5880

想咨询下几个问题

  1. 如果使用 jemalloc 能不能有效降低内存?
  2. 关于内存的占用,主要会集中在哪块?我该如何调优?
  3. 如何查看 rocksdb 内存占用,hugegraph 内部缓存的内存占用
@imbajin
Copy link
Member

imbajin commented Apr 27, 2023

感谢反馈,我们尽快看看給一下相应的测试和回复

@imbajin imbajin added the rocksdb RocksDB backend label Apr 27, 2023
@javeme
Copy link
Contributor

javeme commented May 1, 2023

可以通过/metrics/backend接口获取后端存储的内存占用信息,更多监控接口如下:

  • 127.0.0.1:8080/metrics/backend
  • 127.0.0.1:8080/metrics/system
  • 127.0.0.1:8080/metrics

@mchgood
Copy link
Author

mchgood commented May 2, 2023

可以通过/metrics/backend接口获取后端存储的内存占用信息,更多监控接口如下:

  • 127.0.0.1:8080/metrics/backend
  • 127.0.0.1:8080/metrics/system
  • 127.0.0.1:8080/metrics

这块内存包含 rocksdb 的吗

@imbajin imbajin self-assigned this May 4, 2023
@imbajin imbajin added the improvement General improvement label May 4, 2023
@imbajin
Copy link
Member

imbajin commented May 4, 2023

想咨询下几个问题:

  1. 如果使用 jemalloc 能不能有效降低内存?
  2. 关于内存的占用,主要会集中在哪块?我该如何调优?
  3. 如何查看 rocksdb 内存占用,hugegraph 内部缓存的内存占用
  1. 在高吞吐读写时, 应该是可用 jemalloc 代替默认的 ptmalloc 的, 可以尝试替换并在此 issue 记录反馈. (步骤见后)
  2. 主要应该是 "memtable + block cache + 内存碎片" 三块
  3. 目前查看不太直观, 之后会引入新的方式查看 (BETA)

glibcptmalloc 可能存在内存分配问题:

内存持续增长,无法释放,可能是内存分配器 glibc的问题,导致存在大量的内存碎片无法释放, 从而造成内存泄露

glibcptmalloc 可能存在的问题:

  1. glibc 内存按 arena 分配,arena是一块 连续的内存,默认64M。回收是栈式回收。由于部分内存被缓存在rocksdb的memtable 或 block cache中,造成栈顶的未释放,可能造成整个arena不能回收
  2. 在高并发环境下,为了减少锁的争用,允许存在多个arena。这些arena被不同的线程使用,但彼此之间独立,意味着空闲空间不能合并,造成浪费

解决方案: 替换成 jemalloctcmalloc (可进行对比尝试)

jemalloc 替换方案:

  1. 官方 GitHub 地址下载jemalloc源码按说明编译
  2. 修改(编辑) server 的启动脚本, 添加环境变量 LD_PRELOAD 导入 jemalloc 的 so 二进制依赖文件, 例如
    export LD_PRELOAD=/usr/local/lib/libjemalloc.so
  3. 启动 server, 复现之前的问题步骤, 看是否问题得到解决 (注释后是否重新出现), 如无变化需确认替换是否成功

@imbajin
Copy link
Member

imbajin commented May 29, 2023

@mchgood any update with it?

@mchgood
Copy link
Author

mchgood commented May 30, 2023

@mchgood any update with it?

Yes, I made the settings, but there was no significant change in memory

@imbajin imbajin changed the title [Question] 关于 rocksDB 内存占用的问题 [Question] RocksDB memory occupation out of control May 30, 2023
@imbajin
Copy link
Member

imbajin commented Jun 15, 2023

@mchgood any update with it?

Yes, I made the settings, but there was no significant change in memory

a little strange, how could we reproduce the problem easily?

@imbajin imbajin moved this to 🏗 In progress in HugeGraph Tasks Jun 15, 2023
@imbajin imbajin removed their assignment Jun 15, 2023
@mchgood
Copy link
Author

mchgood commented Jun 25, 2023

@mchgood any update with it? 有什么更新吗?

Yes, I made the settings, but there was no significant change in memory是的,我进行了设置,但内存没有明显变化

a little strange, how could we reproduce the problem easily?有点奇怪,我们怎样才能轻松地重现这个问题呢?

I guess the new environment should also have this problem

@apache apache locked and limited conversation to collaborators Aug 5, 2023
@imbajin imbajin converted this issue into discussion #2268 Aug 5, 2023
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in HugeGraph Tasks Aug 5, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
improvement General improvement rocksdb RocksDB backend
Projects
Status: Done
Development

No branches or pull requests

3 participants