web stats
out of memory reading from mongodb - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2019, 05:09 AM
adidob adidob is offline
Mirth Newb
 
Join Date: Mar 2019
Posts: 8
adidob is on a distinguished road
Default out of memory reading from mongodb

I have a simple javascript that reads from MongoDB and constructs HL7 messages.
It works great but after about 1 hour mirth runs out of memory. The administrator dumpt several error messages, here is the first one:

(com.mirth.connect.connectors.js.JavaScriptReceive r:135): Error executing JavaScript Reader script 1b68468d-52c5-4388-926d-c81b4b350fcd.
com.mirth.connect.server.util.javascript.JavaScrip tExecutorException: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
at com.mirth.connect.server.util.javascript.JavaScrip tUtil.execute(JavaScriptUtil.java:75)
at com.mirth.connect.connectors.js.JavaScriptReceiver .poll(JavaScriptReceiver.java:101)
at com.mirth.connect.donkey.server.channel.PollConnec torJob.execute(PollConnectorJob.java:49)
at org.quartz.core.JobRunShell.run(JobRunShell.java:2 13)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run (SimpleThreadPool.java:557)Caused by: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
at java.base/java.lang.Thread.start0(Native Method)
at java.base/java.lang.Thread.start(Thread.java:813)
at com.mongodb.internal.connection.DefaultServerMonit or.start(DefaultServerMonitor.java:83)
at com.mongodb.internal.connection.DefaultServer.<ini t>(DefaultServer.java:78)
at com.mongodb.internal.connection.DefaultClusterable ServerFactory.create(DefaultClusterableServerFacto ry.java:80)
at com.mongodb.internal.connection.BaseCluster.create Server(BaseCluster.java:376)
at com.mongodb.internal.connection.SingleServerCluste r.<init>(SingleServerCluster.java:58)
at com.mongodb.connection.DefaultClusterFactory.creat eCluster(DefaultClusterFactory.java:187)
at com.mongodb.Mongo.createCluster(Mongo.java:749)
at com.mongodb.Mongo.createCluster(Mongo.java:743)
at com.mongodb.Mongo.<init>(Mongo.java:295)
at com.mongodb.Mongo.<init>(Mongo.java:290)
at com.mongodb.Mongo.<init>(Mongo.java:286)
at com.mongodb.MongoClient.<init>(MongoClient.java:18 0)
at com.mongodb.MongoClient.<init>(MongoClient.java:15 5)
at com.mongodb.MongoClient.<init>(MongoClient.java:14 5)
at jdk.internal.reflect.GeneratedConstructorAccessor1 10.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessor Impl.newInstance(DelegatingConstructorAccessorImpl .java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Construc tor.java:488)
at org.mozilla.javascript.MemberBox.newInstance(Membe rBox.java:159)
at org.mozilla.javascript.NativeJavaClass.constructIn ternal(NativeJavaClass.java:266)
at org.mozilla.javascript.NativeJavaClass.constructSp ecific(NativeJavaClass.java:205)
at org.mozilla.javascript.NativeJavaClass.construct(N ativeJavaClass.java:166)
at org.mozilla.javascript.Interpreter.interpretLoop(I nterpreter.java:1525)
at org.mozilla.javascript.Interpreter.interpret(Inter preter.java:815)
at org.mozilla.javascript.InterpretedFunction.call(In terpretedFunction.java:109)
at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:405)
at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:3508)
at org.mozilla.javascript.InterpretedFunction.exec(In terpretedFunction.java:120)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(JavaScriptTask.java:150)
at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executeScript(JavaScriptUtil.java:542)
at com.mirth.connect.connectors.js.JavaScriptReceiver $JavaScriptReceiverTask.doCall(JavaScriptReceiver. java:159)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.jav a:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

Also here you have my javascript:

var mongoClient = new Packages.com.mongodb.MongoClient("localhost", 27017);
var database = mongoClient.getDatabase("db");
var collection = database.getCollection("foo");

var qdoc = Packages.org.bson.Document.parse(JSON.stringify({" status": { $ne: true }}));
var myDoc = collection.find(qdoc).first();

if (!myDoc) {
return null;
}

var jdoc = myDoc.toJson();
var oJ = JSON.parse(jdoc);

var curdate = DateUtil.getCurrentDate('yyyyMMddhhmmss');

var uQ = Packages.org.bson.Document.parse(JSON.stringify({" uid": oJ.uid}));
var uU = Packages.org.bson.Document.parse(JSON.stringify({$ set : {"status": true}}));
collection.updateOne(uQ, uU);


mongoClient.close();

var msg = <HL7Message/>;

createSegment('MSH', msg);
msg.MSH['MSH.1'] = '|';
msg.MSH['MSH.2'] = '^~\\&';
msg.MSH['MSH.3']['MSH.3.1'] = 'foo';
msg.MSH['MSH.4']['MSH.4.1'] = 'foo';
msg.MSH['MSH.6']['MSH.6.1'] = 'foo';
msg.MSH['MSH.7']['MSH.7.1'] = 'foo';
msg.MSH['MSH.9']['MSH.9.1'] = 'ORU^R01';
msg.MSH['MSH.10']['MSH.10.1'] = 'foo???';
msg.MSH['MSH.11']['MSH.11.1'] = 'P';
msg.MSH['MSH.12']['MSH.12.1'] = '1.0';
msg.MSH['MSH.16']['MSH.16.1'] = '';

var message = SerializerFactory.getSerializer('HL7V2').fromXML(m sg);

return message;
Reply With Quote
  #2  
Old 03-13-2019, 04:32 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 997
agermano is on a distinguished road
Default

Is the server actually out of memory? How much memory is mirth using? How much have you allocated to the JVM? The error description says, "unable to create native thread: possibly out of memory or process/resource limits reached." When mirth runs out of memory, it's much more common to see heap errors than errors creating native threads.

I've never used Mongodb before. Do you need to also close the database and collection? Maybe something isn't getting cleaned up? Typically you would want to have your code in a try block and the close statements in a finally block in case an exception is thrown so you aren't left with lingering connections.
Reply With Quote
  #3  
Old 04-17-2019, 06:51 AM
adidob adidob is offline
Mirth Newb
 
Join Date: Mar 2019
Posts: 8
adidob is on a distinguished road
Default

it looks like it is the message returned by JavaScript reader is leaking memory.

Here you have the last few lines from reader:

"
var message = SerializerFactory.getSerializer('HL7V2').fromXML(m sg);

return message;
"

If I do not return this message then there is no problem with memory, but then what do I have to do to have mirth free this message.
Where my source connector type is "javascript reader" and destination is 'tcp'
Reply With Quote
Reply

Tags
connector, javascript, mongodb, out of memory error

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 02:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation