[英]Node/Mongo application crashes on Amazon EC2 and cannot access the server
我在Amazon EC2實例上具有帶有mongo服務器的節點應用程序。 它運行良好,但是我只是添加了一個新的API調用,每次調用它時,服務器都會凍結,並且我無法在數小時內對其進行訪問/ ssh。 發生這種情況時,我的服務器停機了,這使得依賴它的應用程序無法使用,並且用戶感到憤怒...
這段代碼可以在我的本地主機上完美運行,但是一旦我在服務器上運行它,它就會凍結。 我的想法是它可能導致mongo崩潰? 我不知道為什么會這樣...
如果有人有什么想法可能會出問題,請告訴我。
節點正在使用快遞。 send_error函數將執行res.send({some error})。 db.CommentModel返回mongoose.model('comment',Comment);
在app.js中
app.get('/puzzle/comment/:id', auth.restrict, puzzle.getComments);
在定義getComments的文件中
exports.getComments = function(req, res)
{
var userID = _u.stripNonAlphaNum(req.params.id);
var CommentModel = db.CommentModel;
CommentModel.find({user: userID}, function(e, comments) {
if(e)
{
err.send_error(err.DB_ERROR, res);
}
else if (!comments)
{
err.send_error(err.DB_ERROR, res);
}
else if (comments.length == 0)
{
res.send([]);
}
else
{
var commentIDs = [];
for (var i = 0; i<comments.length; i++)
{
commentIDs.push({_id: comments[i].puzzle});
}
var TargetModel = pApp.findPuzzleModel(_u.stripNonAlphaNum(req.apiKey));
TargetModel.find({removed: false, $or: commentIDs}, function(e, puzzles) {
if(e)
{
err.send_error(err.DB_ERROR, res);
}
else if (!puzzles)
{
err.send_error(err.DB_ERROR, res);
}
else
{
res.send(puzzles);
}
});
}
});
}
聽起來您的查詢正在導致服務器上的某些內容(可能是mongo)消耗大量CPU-因為這通常是導致SSH訪問出現問題的原因。
您應該嘗試閱讀mongo實例的日志,並查看是否存在任何長時間運行的查詢。
Monngodb提供了一個內部分析器,用於檢查長時間運行的命令。 嘗試將長時間運行的概要分析級別設置為1,運行命令並檢查日志文件輸出。
有關探查器的更多詳細信息,請訪問http://www.mongodb.org/display/DOCS/Database+Profiler
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.