Java neo4j, REST and memory

后端 未结 3 960
余生分开走
余生分开走 2021-01-21 21:33

I\'ve deployed an app using neo4j java embedded version under Jersey tomcat for REST API. By measuring memory usage with jconsole I noticed each REST call adds 200Mb of memory (

相关标签:
3条回答
  • 2021-01-21 21:57

    If you're not using Spring or Guice you could get around this by using a static member and static initialization for your neo4J object. If having that static is a deal breaker another option would be to use a static factory to get at a singleton instance of that neo4J object...

    0 讨论(0)
  • 2021-01-21 22:10

    Java won't necessarily reclaim the memory as soon as it is available to be GCed. You might find that you're not seeing significant GC action until you get close to the heap limit. So even if you put your heap limit to 10gb, then you might find memory jumps up again. That isn't necessarily a problem.

    However, to solve the issue of neo using N x Memory, you should consider sharing the embedded instance between all your endpoints. Perhaps by moving it to a service class and having a shared instance between the endpoints. If you are using Spring with Jersey then this would be easy to do as you could wire it in by Spring.

    0 讨论(0)
  • 2021-01-21 22:16

    You must not create Neo4j instance for every request. Please create it just once and then pass it in, either hacky in a static field (as you're resource instance is recreate for each request) or as in Neo4j server with an Provider which is injected with @Context.

    Regarding memory usage. Neo4j builds up internal caches according to your usage to serve the same queries faster the next time. So that might amount for some of the used memory.

    Btw. how large is your graph and what are the typical operations you do?

    0 讨论(0)
提交回复
热议问题