Neo4j CPU utilization reaches 100%. why?
I have a Linux instance on which neo4j is deployed. It is working fine but from 2-3 days sometimes CPU utilization reaches 100% and the DB stop responding to any request.Even, I'm not able to open the DB in the browser. Then, I need to reboot the instance which is not good.
Below the logs which have found in debug.log
old [223790]: Check pointing completed
2018-01-04 17:12:38.329+0000 INFO [o.n.k.i.t.l.p.LogPruningImpl] Log Rotation [6]: Starting log pruning.
2018-01-04 17:12:38.329+0000 INFO [o.n.k.i.t.l.p.LogPruningImpl] Log Rotation [6]: Log pruning complete.
2018-01-04 17:14:20.225+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 389ms.
2018-01-04 17:14:33.212+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 267ms.
2018-01-04 17:16:32.934+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 237ms.
2018-01-04 17:16:34.253+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 317ms.
2018-01-04 17:17:16.896+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 291ms.
2018-01-04 17:17:20.761+0000 ERROR [o.n.b.v.t.BoltProtocolV1] Failed to write response to driver Cannot write to buffer when closed
java.io.IOException: Cannot write to buffer when closed
at org.neo4j.bolt.v1.transport.ChunkedOutput.ensure(ChunkedOutput.java:163)
at org.neo4j.bolt.v1.transport.ChunkedOutput.writeShort(ChunkedOutput.java:94)
at org.neo4j.bolt.v1.packstream.PackStream$Packer.packStructHeader(PackStream.java:427)
at org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter.onSuccess(BoltResponseMessageWriter.java:76)
at org.neo4j.bolt.v1.messaging.MessageProcessingHandler.onFinish(MessageProcessingHandler.java:111)
at org.neo4j.bolt.v1.runtime.BoltStateMachine.after(BoltStateMachine.java:102)
at org.neo4j.bolt.v1.runtime.BoltStateMachine.reset(BoltStateMachine.java:175)
at org.neo4j.bolt.v1.messaging.BoltMessageRouter.lambda$onReset$2(BoltMessageRouter.java:74)
at org.neo4j.bolt.v1.runtime.concurrent.RunnableBoltWorker.execute(RunnableBoltWorker.java:130)
at org.neo4j.bolt.v1.runtime.concurrent.RunnableBoltWorker.run(RunnableBoltWorker.java:91)
at java.lang.Thread.run(Thread.java:748)
I'm not getting why I'm getting this IOException Please help me to find the solution!
Hi @Prateek218,
Could you please share full neo4j.log and debug.log from the database?
Yes, I have attached those file below. debug.log neo4j.log neo4j1.log I have restarted the system after when It reaches the CPU utilization reaches 100%.
@Prateek218 I can see many java.lang.OutOfMemoryError: Java heap space errors in the attached debug.log. They are most likely the reason database becomes unresponsive.
Couple more questions:
- Do you have eager queries that pull a lot of data in memory?
- What heap settings do you have? See operations manual for more info.
- Do you always close sessions/transactions in the JS driver? Maybe share your code here so we can take a look together.
@lutovich I have seen that error but this error was not coming before
java.lang.OutOfMemoryError: Java heap space`
`2018-01-04 12:25:56.389+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 407ms.
2018-01-04 12:27:55.327+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 217ms.
2018-01-04 12:28:21.981+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 291ms.
2018-01-04 12:30:01.829+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 253ms.
2018-01-04 12:30:03.257+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 326ms.
2018-01-04 12:30:30.883+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 222ms.
2018-01-04 12:30:32.491+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 206ms.
2018-01-04 12:32:46.518+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 339ms.
2018-01-04 12:32:50.623+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 399ms.
2018-01-04 12:33:07.717+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 265ms.
2018-01-04 12:33:09.481+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 218ms.
2018-01-04 12:33:23.664+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 268ms.
2018-01-04 12:33:25.858+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 290ms.
2018-01-04 12:34:05.027+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 273ms.
2018-01-04 12:34:14.905+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 335ms.
2018-01-04 12:34:34.084+0000 WARN [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 231ms.
2018-01-04 12:34:34.089+0000 ERROR [o.n.b.v.t.BoltProtocolV1] Failed to write response to driver Cannot write to buffer when closed
java.io.IOException: Cannot write to buffer when closed
at org.neo4j.bolt.v1.transport.ChunkedOutput.ensure(ChunkedOutput.java:163)
at org.neo4j.bolt.v1.transport.ChunkedOutput.writeShort(ChunkedOutput.java:94)
at org.neo4j.bolt.v1.packstream.PackStream$Packer.packStructHeader(PackStream.java:427)
at org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter.onSuccess(BoltResponseMessageWriter.java:76)
at org.neo4j.bolt.v1.messaging.MessageProcessingHandler.onFinish(MessageProcessingHandler.java:111)
at org.neo4j.bolt.v1.runtime.BoltStateMachine.after(BoltStateMachine.java:102)
at org.neo4j.bolt.v1.runtime.BoltStateMachine.reset(BoltStateMachine.java:175)
at org.neo4j.bolt.v1.messaging.BoltMessageRouter.lambda$onReset$2(BoltMessageRouter.java:74)
at org.neo4j.bolt.v1.runtime.concurrent.RunnableBoltWorker.execute(RunnableBoltWorker.java:130)
at org.neo4j.bolt.v1.runtime.concurrent.RunnableBoltWorker.run(RunnableBoltWorker.java:91)
at java.lang.Thread.run(Thread.java:748)
can you please tell me why I am getting this error continously in debug.log?
And yes I'm sharing my code below tell me if I'm doing anything wrong.
const driver= neo4j.driver("bolt://localhost:7687",neo4j.auth.basic("neo4j", "123456"));
const pdbsession = driver.session();
pdbsession.run(query,
{
batch:batchArray
})
.then(function(result){
pdbsession.close();
driver.close();
console.log("Post Insertion Done");
})
.catch(function(err){
console.log(err);
});
here I'm closing the sessions and driver as well as. And I will the check and let you know what heap setting I'm having. Thanks for the help. Waiting for your next response...
I think java.io.IOException: Cannot write to buffer when closed happens because you close driver after every operation. Neo4j databases prior to https://github.com/neo4j/neo4j/pull/9658 print this kind of stacktrace when connection from driver is closed. It is harmless in this case.
It is highly recommended to create a singe driver instance per application and not for every operation. Could you please refactor your code to do so?
Please, also share heap settings for the database and typical queries that are executed.
So, Can you please help when should I close the driver.
below are the heap setting.
dbms.memory.pagecache.size=6G
dbms.memory.heap.initial_size=4G
dbms.memory.heap.max_size=4G
below are the typical queries which I'm executing.
- Query for getting Data from Database.
match (p:Post)-[r:CATEGORY_IS]-(c:'+req.params.title+') match (p)-[re:LANG_IS]-(l) where l.name="'+req.params.language+'" OR l.name="'+req.params.language2+'" match (p)-[t:POST_BELONGS_TO_SRC]-(pa:PostSourceName) return p.uuid,p.post_title,p.post_description,p.post_source_publish_time,collect(distinct p.post_source_link), p.post_main_img_link,p.post_likes_count,pa.src_type,pa.src_name, pa.uuid, pa.src_profile_image_url, pa.src_profile_image_default,l.name,p.video_link,labels(p),p.post_facebook_id order by p.post_source_publish_time DESC limit 100 - Query for inserting Data in Database.
UNWIND {batch} as data merge (p:Post:PostTypePhotoSingle{post_facebook_id: data.post_facebook_id}) ON CREATE SET p.uuid=data.uuid,p.post_source_link=data.post_source_link,p.post_title=data.post_title,p.post_description=data.post_description,p.post_source_publish_time=data.post_source_publish_time,p.post_fetch_time=timestamp(),p.post_likes_count=data.post_likes_count,p.post_reaction_count=0,p.post_reaction_type=0,p.post_downvotes=0,p.post_spam_count=0,p.post_shared_count=0,p.post_viewed_count=0,p.post_bookmarked_count=0,p.post_main_img_link=data.post_main_img_link,p.post_main_img_width=1,p.post_main_img_height=1,p.post_detail_view_count=0,p.post_source_name=data.post_source_name ON MATCH SET p.post_title=data.post_title,p.post_description=data.post_description,p.post_main_img_link=data.post_main_img_link,p.post_source_link=data.post_source_link with p,data optional match (pa:PostSourceName:Facebook{src_facebook_id:data.src_facebook_id}) optional match (l:Language{name:data.language}) optional match (t:CategoryType{name:data.tabname}) with p,pa,l,t,data merge (p)-[r:POST_BELONGS_TO_SRC{name:"POST_BELONGS_TO_SRC"}]->(pa) merge (pa)-[rel:HAS_POST{name:"HAS_POST"}]->(p) merge (p)-[rela:LANG_IS{name:"LANG_IS"}]->(l) merge (p)-[relat:CATEGORY_IS{name:"CATEGORY_IS"}]->(t)
Driver should be created when application starts and closed when it shuts down. I guess in NodeJS you could use process.on('exit', function(){...}) or process.on('SIGTERM', function(){...}) and close driver inside the callback function.
Heap and page cache look totally fine to me. How large is your database? First query might perform an eager operation to execute ORDER BY, but it'll only be a problem if query returns a lot of data. How many records does it return without LIMIT 100?
Actually, in my app, these drivers are defined for cron which are running after every 10 minutes of interval. which means NodeJS app never shutdowns. So, what you should recommend for me, how can I close the driver in my use case.
Now, around 1 million nodes are there in Database which growing continuously Day by day. First Query returns around 20k records per request. It is also increasing day by day.
And Can suggest me if I'll use Neo4j Rest API instead of neo4j-driver for inserting data into the database will be the good or using neo4j-driver will be the good option?
@Prateek218 it is still better to keep a single driver instance and shut it down in process.on('SIGTERM', function(){...}) listener just in case. I think REST API does not really have any advantages over this driver.
Could you please also share a thread dump for the neo4j database?
It can be obtained with command jstack <PID of the database process>
Ok, so you mean that I need to instantiate the driver and then close on process.on('SIGTERM', function(){...}).It won't affect the performance of the Database.
yes, I can share but where I can find the PID of the database process.
Can you please tell me?
I think having a singe driver instance might help, yes.
To find PID you could execute a jps command which lists all running java processes for the current user. Then pick PID corresponding to CommunityEntryPoint or EnterpriseEntryPoint depending on the edition you use.
It might look smth like:
$ jps
65490 RemoteMavenServer
66196 CommunityEntryPoint <-- this is the one we need
64933 Launcher
61178 NailgunRunner
66202 Jps
57501
$ jstack 66196 <-- use PID from the previous step
2018-01-08 17:06:21
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.141-b15 mixed mode):
... rest of the thread dump ...
If you start database manually like ./bin/neo4j start or ./bin/neo4j console then it should print the PID in the startup message like ... Started neo4j (pid 66196) ....
I tried to find PID as you suggested, but it is only returning below as I mentioned.
$ jps
7756 Jps
I'm not able to find the process id for the database. Thank You.
You need to execute jps using same user that has started the database.
Command might be sudo -u <user that started neo4j> jps.
Finally, got the PID but see the below response.
ubuntu@ip-172-32-28-106:~$ sudo -u root jps
10828 Jps
1149 CommunityEntryPoint
ubuntu@ip-172-32-28-106:~$ jstack 1149
1149: Operation not permitted
Please also execute jstack as user root
Getting this.
ubuntu@ip-172-32-28-106:~$ sudo -u root jstack 1149
1149: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
I do not think root is the user who launched neo4j. Please figure out the correct user or try -F flag as the message suggests sudo -u root jstack -F 1149.
Can you also upgrade to neo4j 3.3.1?
Result
Attaching to process ID 1149, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.151-b12
Deadlock Detection:
java.lang.RuntimeException: Unable to deduce type of thread from address 0x00007fc9280d8000 (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, or SurrogateLockerThread)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:166)
at sun.jvm.hotspot.runtime.Threads.first(Threads.java:150)
at sun.jvm.hotspot.runtime.DeadlockDetector.createThreadTable(DeadlockDetector.java:149)
at sun.jvm.hotspot.runtime.DeadlockDetector.print(DeadlockDetector.java:56)
at sun.jvm.hotspot.runtime.DeadlockDetector.print(DeadlockDetector.java:39)
at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:62)
at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
at sun.tools.jstack.JStack.main(JStack.java:106)
Caused by: sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address 0x00007fc9280d8000
at sun.jvm.hotspot.runtime.InstanceConstructor.newWrongTypeException(InstanceConstructor.java:62)
at sun.jvm.hotspot.runtime.VirtualConstructor.instantiateWrapperFor(VirtualConstructor.java:80)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:162)
... 17 more
Can't print deadlocks:Unable to deduce type of thread from address 0x00007fc9280d8000 (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, or SurrogateLockerThread)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
at sun.tools.jstack.JStack.main(JStack.java:106)
Caused by: java.lang.RuntimeException: Unable to deduce type of thread from address 0x00007fc9280d8000 (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, or SurrogateLockerThread)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:166)
at sun.jvm.hotspot.runtime.Threads.first(Threads.java:150)
at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:75)
at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
... 6 more
Caused by: sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address 0x00007fc9280d8000
at sun.jvm.hotspot.runtime.InstanceConstructor.newWrongTypeException(InstanceConstructor.java:62)
at sun.jvm.hotspot.runtime.VirtualConstructor.instantiateWrapperFor(VirtualConstructor.java:80)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:162)
... 14 more
Yes, I can Upgrade
- But if I'll upgrade the database then it will stop or while running it will be upgraded?
- when I check version in Linux server it shows below as I mentioned.
ubuntu@ip-172-32-28-106:~$ neo4j version
neo4j 3.2.0
But in browser, it shows different version 3.0.1 why?
Ok, -F does not work. You have invoke jstack with the correct user or JVM is very hung (which seems unlikely).
Database has to be shut down in order to perform an upgrade.