内存不足问题 – 一旦我开始我的Java应用程序,Mongo就会死亡

我有一个独立的应用程序,我正在尝试创build5个线程为每个线程创build一个mongoclient并在MongoDB中保存细节,然后closuresmongoclient。

当我启动我的mongo服务,它正在运行,但一旦我开始我的Java应用程序一段时间后,我的mongo服务正在被杀死,我可以在syslog中看到下面的错误。

Out of memory: Kill process 12715 (mongod) score 433 or sacrifice child\\ kernel: [2946780.340246] Killed process 12715 (mongod) total-vm:6646800kB, anon-rss:6411432kB, file-rss:0kB 

我正在使用Linux服务器,它有10GB内存。 据我所知,我们可以在MongoDB中做成千上​​万的事务。 而在我开始之前,我可以看到一段时间后我可以看到空闲的内存,上面的错误。

不知道到底该怎么做,我们需要设置任何东西在Linux服务器来处理多个mongo请求? 或者我需要增加mongo服务的限制吗?

任何人都可以在这个build议我?

提前致谢。

在执行我的Java应用程序之前和之后,免费-m的o / p如下所示:

之前:

  total used free shared buffers cached Mem: 14032 7646 6385 54 4 153 -/+ buffers/cache: 7489 6542 Swap: 0 0 0 

后:

  total used free shared buffers cached Mem: 14032 13845 186 54 106 4131 -/+ buffers/cache: 9607 4425 Swap: 0 0 0 

以下是来自mongod.conf的详细信息

 # mongod.conf storage: dbPath: /xxx/xxx journal: enabled: true systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log net: port: 27017 bindIp: 127.0.0.1,xx.xx.xx.xx processManagement: fork: true security: authorization: enabled 

cat /proc/<PId>/limits

 cat /proc/17694/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 112088 112088 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 112088 112088 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us 

ps xua | grep java结果:::

  root 17142 0.4 3.1 5645648 453180 pts/0 Sl Sep04 2:27 java -d64 -Xms1024m -Xmx2048m -server -cp bin:lib/* javaclassname -resourceDir /xxx/bin -dataDir /xxx/data root 17491 22.1 11.2 5653432 1610716 pts/0 Sl Sep04 115:14 java -d64 -Xms1024m -Xmx2048m -server -cp bin:lib_new/* javaclassname -resourceDir /xxx/bin -dataDir /xxx/data -outConfigPath /xxx/xxx.xml -outCatBrandPath /xxx/xxx.xml -outCatAndSunCatPath /xxx/xxx.xml xxx 19223 3.5 22.1 20396560 3184668 ? Sl Aug28 398:11 /usr/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/elasticsearch-5.4.0 -cp /elasticsearch-5.4.0/lib/* org.elasticsearch.bootstrap.Elasticsearch root 21617 2.2 21.7 18549248 3124416 ? Sl Aug28 247:34 /usr/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-8.0.30/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/opt/apache-tomcat-8.0.30/endorsed -classpath /opt/apache-tomcat-8.0.30/bin/bootstrap.jar:/opt/apache-tomcat-8.0.30/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-8.0.30 -Dcatalina.home=/opt/apache-tomcat-8.0.30 -Djava.io.tmpdir=/opt/apache-tomcat-8.0.30/temp org.apache.catalina.startup.Bootstrap start 

swapon -s输出:

 Filename Type Size Used Priority 

看起来操作系统没有物理内存,而且由于你的服务器似乎没有configuration任何交换,所以内核的内存不足的杀手(OOM-killer)开始并终止进程来释放一些RAM(在这种情况下,它是mongodb,但可以是其他)。

你应该在该服务器上创build一个交换分区。