【发布时间】:2014-02-06 02:42:10
【问题描述】:
最近我的一些流星方法神秘地变慢了。虽然它们过去非常活泼,但很多都需要 10 秒左右。
不会导致减速的原因:
- 附加功能,代码库中速度较慢的部分没有明显改变
- 机器负载(cpu 负载徘徊在 30% 左右)
- 额外的数据库负载(未添加新查询)
- 返回数据的传输时间(返回未定义)
- 阻塞方法(我已经尝试在方法中使用 this.unblock())
我在服务器端和客户端都使用了 console.time() / console.timeEnd() 进行了调试。服务器端代码运行大约需要 0.3 秒,但客户端直到流星.call() 后大约 11 秒才收到回调...
这是服务器方法:
function cancelSomething(somethingId, reason) {
console.time('cancelSomething method');
check(somethingId, String);
check(reason, String);
if (!AuthChecks()))
throw new Meteor.Error(401, 'Not Authorized');
var something = MySomethings.findOne({'_id': somethingId});
if (!something)
throw new Meteor.Error(404, 'Something not found');
var returnVal = SomethingService.cancel(something, reason);
console.timeEnd('cancelSomething method'); // <--- prints "cancelSomething 350ms" or there abouts
return returnVal;
}
客户端:
console.time('meteorCall');
Meteor.call('cancelSomething', this._id, reason, function(err) {
if (err) {
console.log('an error occurred', err);
}
console.timeEnd('meteorCall'); // <--- prints "meteorCall 11500" or so
});
编辑: 我注意到与数据库中“某些东西”中的文档数量存在一些相关性。 w/ 500 个文档大约需要 1 秒才能在客户端收到返回,5000 个大约需要 8.5 秒 ...
【问题讨论】:
-
当 Meteor 没有作为副本集的一部分运行时,10 秒是 mongo 的默认轮询间隔。我想知道您的数据库设置是否有问题...
-
@AndrewMao 很好地考虑了轮询,但这是一种流星方法,我正在测试 Meteor.call('cancelSomething') 的回调何时发生。方法调用/回调不应该与对集合的响应式更新有任何关系。
标签: meteor