【发布时间】:2015-02-10 19:17:59
【问题描述】:
我正在使用 MEAN 堆栈制作 Angular 应用程序。我的快递应用程序中有以下代码:
router.post('/', function (req, res) {
var username = req.user.username;
var items = req.body.items;
if (items) {
items = JSON.parse(items);
} else {
return
}
if (!username) {
res.status(401).send('There is no username');
return
}
User.findOne({username: username}, function (err, user) {
if (err) {
throw err;
}
if (!user) {
res.status(401).send('No user with that username');
}
if (typeof items === 'number') {
console.log('yes');
user.update({$push: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
} else {
user.update({$pushAll: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
}
});
});
在角度方面,每当我尝试连续发出超过 6 个推送(更新)请求时,节点程序都会冻结(没有更新,没有记录发布请求)一两分钟,然后发布请求是已收到。发生这种情况有什么原因吗?当节点冻结时,没有任何工作(它不提供请求)但不会崩溃。
这里是一个快递日志的例子:
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
// Very long pause
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
【问题讨论】:
标签: angularjs node.js mongodb mongoose