国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

node.js - mongodb中數(shù)據(jù)find出來,提示process out of memory,數(shù)據(jù)大小并沒有超過NodeJS默認(rèn)的512MB

瀏覽:120日期:2024-07-25 14:30:06

問題描述

使用mongoose從數(shù)據(jù)庫中一次性find出數(shù)據(jù),提示:

node.js - mongodb中數(shù)據(jù)find出來,提示process out of memory,數(shù)據(jù)大小并沒有超過NodeJS默認(rèn)的512MB

但是我查了default the memory limit of Node.js is 512 mb,我的數(shù)據(jù)集合大小只有127MB,并沒有超過這個(gè)大小,也不需要設(shè)置--max_old_space_size吧,求解

代碼如下:

//model.jsvar LagouInfo = require(’./schema.js’)var DesData = require(’./des.js’);var async = require(’async’);LagouInfo.find({}, function(res){ res.forEach(function(item){if(item.content.trim()){ var sumSalary = 0; item.salary.forEach(function(sitem){var num;if(sitem.indexOf(’-’) == -1){ num = sitem.replace(/D+/, ’’);}else{ num = parseInt(sitem.trim().split(’-’)[1]);}// console.log(sitem, num);sumSalary += num; }) var tags = item.tag.trim().split(’,’); tags.forEach(function(tag){DesData.update({’tag’: tag}, {$push: {’content’: item.content}});DesData.update({’tag’: tag}, {$inc: {’total’: item.total}});DesData.update({’tag’: tag}, {$inc:{’salary’: sumSalary}}); })} })})

//des.jsvar mongoose = require(’./db.js’), Schema = mongoose.Schema;var InfoSchema = new Schema({ tag: {type: String}, content: {type: Array}, total: {type: Number}, salary: {type: Number}, });var Data = mongoose.model(’desdata’, InfoSchema, ’desdata’);function insert(obj, callback){ var data = new Data(obj); data.save(function(err, res){if(err) console.log(’Error:’ + err);else callback(null, res); })}function update(conditions, updateStr){ Data.update(conditions, updateStr, function(err, res){if(err) console.log(’Error:’ + err);else console.log(’Update Success’);// else callback(null, res); })}function find(conditions, callback){ Data.find(conditions, function(err, res){if(err) console.log(’Error:’ + err);else callback(res); }) // return Data.find(conditions).exec();}module.exports = { insert: insert, update: update, find: find}

//schema.jsvar mongoose = require(’./db.js’), Schema = mongoose.Schema;var LagouSchema = new Schema({ name: {type: String}, cid: {type: Number}, process: {type: String}, content: {type: String}, url: {type: String}, tag: {type: String}, total: {type: Number}, salary: {type: Array}});var Lagou = mongoose.model(’lagou’, LagouSchema, ’lagou’);function update(conditions, update){ Lagou.update(conditions, update, function(err, res){if(err) console.log(’Error:’ + err);else console.log(’Res:’ + res); })}function del(conditions){ Lagou.remove(conditions, function(err, res){if(err) console.log(’Error:’ + err);else console.log(’Res:’ + res); })}function find(conditions, callback){ Lagou.find(conditions, function(err, res){if(err) console.log(’Error:’ + err);else callback(res); })}module.exports = { find: find, del: del, update: update}

//db.jsvar mongoose = require(’mongoose’), DB_URL = ’mongodb://localhost:27017/result’;mongoose.Promise = global.Promise;mongoose.connect(DB_URL);//連接成功mongoose.connection.on(’connected’, function(){ console.log(’Mongoose connection open to ’ + DB_URL);})//連接異常mongoose.connection.on(’error’, function(err){ console.log(’Mongoose connection error: ’ + err);})//連接斷開mongoose.connection.on(’disconnected’, function(){ console.log(’Mongoose connection disconnected’);})module.exports = mongoose;

============更新2017-01-12===================

嘗試設(shè)置了--max_old_space_size還是報(bào)錯(cuò)

node.js - mongodb中數(shù)據(jù)find出來,提示process out of memory,數(shù)據(jù)大小并沒有超過NodeJS默認(rèn)的512MB

報(bào)錯(cuò)內(nèi)容:

$ node --max_old_space_size=2000 models/test.jsMongoose connection open to mongodb://localhost:27017/result<--- Last few GCs ---> 251717 ms: Mark-sweep 1989.2 (2067.0) -> 1989.3 (2067.0) MB, 1564.0 / 0 ms [allocation failure] [scavenge might not succeed]. 253271 ms: Mark-sweep 1989.3 (2067.0) -> 1989.2 (2067.0) MB, 1554.2 / 0 ms [allocation failure] [scavenge might not succeed]. 254868 ms: Mark-sweep 1989.2 (2067.0) -> 1989.3 (2067.0) MB, 1597.0 / 0 ms [last resort gc]. 256434 ms: Mark-sweep 1989.3 (2067.0) -> 1989.2 (2067.0) MB, 1566.2 / 0 ms [last resort gc].<--- JS stacktrace --->==== JS stack trace =========================================Security context: 00000394003B4639 <JS Object> 2: /* anonymous */(aka /* anonymous */) [D:softwareself_learnPaperpreprocessnode_modulesmongodb-corelibconnectionpool.js:~1096] [pc=000002BA3DA6C022] (this=00000394003041B9 <undefined>) 3: waitForAuth(aka waitForAuth) [D:softwareself_learnPaperpreprocessnode_modulesmongodb-corelibconnectionpool.js:1088] [pc=000002BA41DE1FBC] (this=00000394003041B9 <undefined>,cb=0000...FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

問題解答

回答1:

感覺這個(gè)報(bào)錯(cuò)和mongodb沒有關(guān)系了 是node程序的內(nèi)存問題吧

試試這樣子可以嗎

node --max_old_space_size=2000 server.js

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

回答2:

首先,數(shù)據(jù)大小在數(shù)據(jù)庫里面看到的和程序讀到內(nèi)存里的體積是不同的。建議加些條件,縮小數(shù)據(jù)量,看是否有問題?然后加多點(diǎn)數(shù)據(jù),看是否有問題?看看有問題的時(shí)候記錄條數(shù)是多少。第二,我怎么覺得你這函數(shù)寫的有點(diǎn)問題?DesData.update是異步方法,你用的是同步寫法,然后我看你的tags.foreach方法應(yīng)該是循環(huán)多次的,多少次我不清楚,但應(yīng)該挺大的,導(dǎo)致你oom問題的很可能出現(xiàn)在這里----堆積太多異步方法等待執(zhí)行了。而且你這樣寫異步真的好嗎。建議用async包來改一下你的代碼,最好用forEachLimit,手機(jī)打字就不直接幫你改代碼了,如果還不行,我上電腦的時(shí)候幫你改。

回答3:

能否貼出您的部分代碼,看看代碼是否有環(huán)節(jié)存在潛在Issue。

主站蜘蛛池模板: 亚洲精品第五页中文字幕 | 看真人视频一级毛片 | 精品国产日韩亚洲一区在线 | 国产高清一国产免费软件 | 免费观看欧美一级高清 | 国产香蕉影视院 | 萌白酱喷水福利视频在线 | 无码免费一区二区三区免费播放 | 国产一区二区影视 | 好叼操这里只有精品 | 亚洲一区二区在线成人 | 国产午夜不卡在线观看视频666 | 荡女妇边被c边呻吟久久 | 成人福利网站含羞草 | 美女成人网| 国产精品观看在线亚洲人成网 | 毛片免费看 | 亚洲精品一区二区三区四区 | 亚洲一区免费在线观看 | 中文字幕一区二区精品区 | 好爽~好硬~好紧~蜜芽 | 日韩视频欧美视频 | 男女性高清爱潮视频免费观看 | 看v片| 中文字幕日韩在线 | 亚洲免费专区 | 精品在线免费视频 | 国产免费福利体检区久久 | 操小美女| 神马国产| 国产精品久久久久影院色老大 | 色综合天天综合网看在线影院 | xoxoxoxo欧美性护士 | 明星国产欧美日韩在线观看 | 久久久久久久国产精品视频 | 国产精品久久久久a影院 | 国产成人亚洲综合无 | 欧美成人免费在线观看 | 日韩三级在线观看 | 国产成人福利视频网站 | 在线免费观看成年人视频 |