生产环境前段时间neo4j图数据库总是在凌晨定时任务删除过期节点时报内存占用过高的告警,研究下怎么配置参数:

neo4j内存结构:

neo4j内存组成

OS保留:OS内存、Lucene索引缓存
页面缓存:图数据缓存、索引缓存
jvm堆:图查询、图管理、事务状态(可选)
事务状态
neo4j memory management

推荐的内存参数:

分配了3.6G jvm堆内存,2G 页面缓存,剩余2.6G空闲内存和 native memory 给 Lucene 和 Netty

一个收获:很多中间件jvm内存并不是一定需要占大头,例如某些MQ和缓存会使用 native memory 来避免jvm频繁垃圾回收带来的性能问题;以及像neo4j的Lucene引擎使用系统分页缓存

三个建议:

索引文件太大时,多剩点内存给OS
并发事务和update语句越多,分配的jvm堆内存也要越大(别超过31G)
jvm堆内存设置初始值和最大值一致,因为jvm更改堆大小时会触发full GC影响性能

syf@syf-ubuntu ~/o/neo4j-community-3.5.8 [1]> bin/neo4j-admin memrec --memory=8g
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
# Memory settings recommendation from neo4j-admin memrec:
#
# Assuming the system is dedicated to running Neo4j and has 8g of memory,
# we recommend a heap size of around 3600m, and a page cache of around 2g,
# and that about 2600m is left for the operating system, and the native memory
# needed by Lucene and Netty.
#
# Tip: If the indexing storage use is high, e.g. there are many indexes or most
# data indexed, then it might advantageous to leave more memory for the
# operating system.
#
# Tip: The more concurrent transactions your workload has and the more updates
# they do, the more heap memory you will need. However, don't allocate more
# than 31g of heap, since this will disable pointer compression, also known as
# "compressed oops", in the JVM and make less effective use of the heap.
#
# Tip: Setting the initial and the max heap size to the same value means the
# JVM will never need to change the heap size. Changing the heap size otherwise
# involves a full GC, which is desirable to avoid.
#
# Based on the above, the following memory settings are recommended:
dbms.memory.heap.initial_size=3600m
dbms.memory.heap.max_size=3600m
dbms.memory.pagecache.size=2g

参考:

https://neo4j.com/docs/operations-manual/3.5/performance/memory-configuration/

https://neo4j.com/docs/operations-manual/3.5/tools/neo4j-admin-memrec/

标签: neo4j

添加新评论