记一次Meteor打包meteor build后,表的发布和订阅变慢
特殊点:由于这个项目要和python通信,python直接在我的mongodb数据库表插入一条数据,我通过他插入的数据做相应的响应。在开发环境挺好的,但打包后,表的发布和订阅突然变慢了大概7秒左右。(开发环境本来python插入数据马上就能订阅到的,但打包之后python插入数据要等7秒才会订阅到变化)查了很多问题都没解决,好苦,后来领导发来了几个参数,配上去就解决了,太厉害了,感谢!
控制meteor表的发布和订阅频率参数pollingThrottleMs: 50和pollingIntervalMs: 200,详细配置如下:
代码如下:
在服务器端 /server/main.js
message = new Mongo.Collection('message')
if(Meteor.isServer){
Meteor.publish("currentRoom", function () {
return message.find({}, {
pollingThrottleMs: 50, // 主要是这个参数
pollingIntervalMs: 200 // 和这个参数
});
});
}
在客户端 /client/main.js
// 订阅
Meteor.subscribe('currentRoom', function() {
message.find().observe({
added:function(data){
let arr = message.find().fetch();
console.log('变化:',arr);
},
removed:function() {
console.log("deleted Detele :");
}
})
})