mongodb - MongoException : java. lang.OutOfMemoryError:超出了GC开销限制

标签 mongodb garbage-collection out-of-memory mongo-java mongo-java-driver

我正在批量写入MongoDB并获得OOM异常(java.lang.OutOfMemoryError:超出了GC开销限制)。我有两个问题:

  • OOM是否来自Mongo客户端驱动程序或MongoDB服务器?
  • 是否有OOM发生原因的线索?

  • FO 2016-11-15 15:19:10,437 - [TS] org.mongodb.driver.cluster info(71) - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, all=[ServerDescription{address=mongo.server1-or:30000, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=mongo.server2:30000, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=mongo.server3:30000, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out INFO 2016-11-15 15:19:11,448 - [TS] org.mongodb.driver.cluster info(71) - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, all=[ServerDescription{address=mongo.server1-or:30000, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=mongo.server2:30000, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=mongo.server3:30000, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out INFO 2016-11-15 15:19:14,324 - [TS] org.mongodb.driver.cluster info(76) - Exception in monitor thread while connecting to server mongo.server2:30000 com.mongodb.MongoException: java.lang.OutOfMemoryError: GC overhead limit exceeded at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:125) at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded INFO 2016-11-15 15:19:14,325 - [TS] com.xyz.executors.ConsumeMessageTask run(45) - Scheduled thread pool will write to MongoDB INFO 2016-11-15 15:19:14,325 - [TS] org.mongodb.driver.connection info(71) - Opened connection [connectionId{localValue:28690}] to mongo.server3:30000 ERROR 2016-11-15 15:19:17,353 - [TS] com.xyz.executors.ConsumeMessageTask run(117) - An error occurred when bulk writing to MongoDB com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongo.server1-or:30000, type=UNKNOWN, state=CONNECTING}, {address=mongo.server2:30000, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoException: java.lang.OutOfMemoryError: GC overhead limit exceeded}, caused by {java.lang.OutOfMemoryError: GC overhead limit exceeded}}, {address=mongo.server3:30000, type=UNKNOWN, state=CONNECTING}] at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369) at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101) at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:75) at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:71) at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:219) at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:168) at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:74) at com.mongodb.Mongo.execute(Mongo.java:781) at com.mongodb.Mongo$2.execute(Mongo.java:764) at com.mongodb.DBCollection.executeBulkWriteOperation(DBCollection.java:2195) at com.mongodb.DBCollection.executeBulkWriteOperation(DBCollection.java:2188) at com.mongodb.BulkWriteOperation.execute(BulkWriteOperation.java:121) at com.xyz.executors.ConsumeMessageTask.run(ConsumeMessageTask.java:112) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) `

    最佳答案

    您的stacktrace指出该错误源自此行:
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369) at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)...
    因此客户端在尝试连接到服务器时会超时。
    从服务器收到的信息在上面的行中:
    Client view of cluster state is {type=UNKNOWN, servers=[ {address=mongo.server1-or:30000, type=UNKNOWN, state=CONNECTING}, {address=mongo.server2:30000, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoException: java.lang.OutOfMemoryError: GC overhead limit exceeded}, caused by {java.lang.OutOfMemoryError: GC overhead limit exceeded}}, {address=mongo.server3:30000, type=UNKNOWN, state=CONNECTING}]
    这意味着OutOfMemoryError来自mongo.server2。最好检查该服务器的日志以查看其发生原因,但是
    大量的写作可能与此有关。可能是mongo.server2跟不上同步您写入主服务器的数据。

    关于mongodb - MongoException : java. lang.OutOfMemoryError:超出了GC开销限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40606470/

    相关文章:

    ruby - Ruby 2.2 中的垃圾收集器引发意想不到的 CoW

    java - 以最小内存消耗写入文件的设计模式

    c - 内存不足杀死

    mongodb - 可以使用 MongoDB 制作关系数据库吗?

    MongoDB - 计算包含数组元素的数组中的值的$sum

    使用大部分堆的 Android 应用程序,无法成功识别内存泄漏

    c# - ReRegisterForFinalize SuppressFinalize 现实生活中的例子

    java - 在线程的 run() 中捕获 OutofMemoryError 是否明智?

    java - "No property exists found for type"... 将 QueryDslPredicateExecutor 与 MongoDB 和 Spring-Data 一起使用时

    mongodb - 在mongodb中获取具有相同属性的文档