No announcement yet.

out of memory reading from mongodb

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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(
    at com.mirth.connect.connectors.js.JavaScriptReceiver .poll(
    at torJob.execute(
    at 13)
    at org.quartz.simpl.SimpleThreadPool$ ( 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(
    at com.mongodb.internal.connection.DefaultServerMonit or.start(
    at com.mongodb.internal.connection.DefaultServer.<ini t>(
    at com.mongodb.internal.connection.DefaultClusterable ServerFactory.create(DefaultClusterableServerFacto
    at com.mongodb.internal.connection.BaseCluster.create Server(
    at com.mongodb.internal.connection.SingleServerCluste r.<init>(
    at com.mongodb.connection.DefaultClusterFactory.creat eCluster(
    at com.mongodb.Mongo.createCluster(
    at com.mongodb.Mongo.createCluster(
    at com.mongodb.Mongo.<init>(
    at com.mongodb.Mongo.<init>(
    at com.mongodb.Mongo.<init>(
    at com.mongodb.MongoClient.<init>( 0)
    at com.mongodb.MongoClient.<init>( 5)
    at com.mongodb.MongoClient.<init>( 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
    at org.mozilla.javascript.MemberBox.newInstance(Membe
    at org.mozilla.javascript.NativeJavaClass.constructIn ternal(
    at org.mozilla.javascript.NativeJavaClass.constructSp ecific(
    at org.mozilla.javascript.NativeJavaClass.construct(N
    at org.mozilla.javascript.Interpreter.interpretLoop(I
    at org.mozilla.javascript.Interpreter.interpret(Inter
    at org.mozilla.javascript.ContextFactory.doTopCall(Co
    at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr
    at org.mozilla.javascript.InterpretedFunction.exec(In
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(
    at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executeScript(
    at com.mirth.connect.connectors.js.JavaScriptReceiver $JavaScriptReceiverTask.doCall(JavaScriptReceiver. java:159)
    at com.mirth.connect.server.util.javascript.JavaScrip
    at java.base/ a:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.base/java.util.concurrent.ThreadPoolExecutor$ (
    at java.base/

    Also here you have my javascript:

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

    var qdoc ={" 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 ={" uid": oJ.uid}));
    var uU ={$ set : {"status": true}}));
    collection.updateOne(uQ, uU);


    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;

  • #2
    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.


    • #3
      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'