我正在批量写入MongoDB时遇到了内存溢出异常 (java.lang.OutOfMemoryError: GC overhead limit exceeded)。我有两个问题:
- 这个OOM是来自Mongo Client Driver还是MongoDB Server?
- 有什么线索可以说明为什么会出现OOM?
FO 2016-11-15 15:19:10,437 - [TS] org.mongodb.driver.cluster info(71) - WritableServerSelector未从集群描述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}]}中选择服务器。在超时前等待30000毫秒
INFO 2016-11-15 15:19:11,448 - [TS] org.mongodb.driver.cluster info(71) - WritableServerSelector未从集群描述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}]}中选择服务器。在超时前等待30000毫秒
INFO 2016-11-15 15:19:14,324 - [TS] org.mongodb.driver.cluster info(76) - 在连接到服务器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) - 计划线程池将写入MongoDB
INFO 2016-11-15 15:19:14,325 - [TS] org.mongodb.driver.connection info(71) - 已打开连接[connectionId{localValue:28690}]到mongo.server3:30000
ERROR 2016-11-15 15:19:17,353 - [TS] com.xyz.executors.ConsumeMessageTask run(117) - 在批量写入MongoDB时发生错误
com.mongodb.MongoTimeoutException: 等待匹配WritableServerSelector的服务器超时,等待时间为30000毫秒。集群状态的客户端视图为{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