如何使用pollingThrottle和pollingInterval? [英] How to use pollingThrottle and pollingInterval?

查看:294
本文介绍了如何使用pollingThrottle和pollingInterval?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此我的应用程序中有一些不需要立即反应的东西,并在文档中找到了有关属性 pollingThrottleMs pollingIntervalMs 的信息。因此,这里基本上是有关我设法找到的那些属性的所有信息:

So I have some things in my application that I don't need an immediate reactivity and found out about properties pollingThrottleMs and pollingIntervalMs in the documentation. So here is basically all the information about those properties I managed to find:


pollingIntervalMs编号
(仅限服务器)在服务器上观察时轮询此查询。以毫秒为单位。默认值为10秒。

pollingIntervalMs Number (Server only) How often to poll this query when observing on the server. In milliseconds. Defaults to 10 seconds.

pollingThrottleMs编号
(仅服务器)允许两次重新轮询之间的最短时间。增加此值将节省CPU和mongo负载,但代价是对
用户的更新速度较慢。不建议降低此值。以毫秒为单位。默认
为50毫秒。

pollingThrottleMs Number (Server only) Minimum time to allow between re-polling. Increasing this will save CPU and mongo load at the expense of slower updates to users. Decreasing this is not recommended. In milliseconds. Defaults to 50 milliseconds.

所以第一个问题-我不清楚这两个属性之间的区别是什么,也许有人可以向我解释? (pollingThrottleMs是订阅更新的速率限制,而pollingIntervalMs是我们检查更新的频率,据我所知)pollingIntervalMs的默认值为10s?真?那么,为什么财产中有女士的名字呢?

So the first question - it's not exactly clear to me what is the difference between those properties, maybe someone could explain it to me? (pollingThrottleMs is kind of rate limit for subscription updates and pollingIntervalMs is how often we check for updates as I understand) Also pollingIntervalMs default is 10s? Really? Why is the property have Ms in the name then? That can't be right.

然后,我尝试在查询中设置这些属性,如下所示:

Then later I tried to set those properties on my query like this:

Meteor.publish("currentRoom", function (roomName) {
    return Rooms.find({name: roomName}, {
      pollingThrottleMs: 5000,
      pollingIntervalMs: 5000
    });
});

我期望一个客户端更新到另一个客户端的反应性更新之间会有5s的延迟,但是不会似乎工作。我什至在观察中设置了断点,并立即得到通知。难道我做错了什么?

I expected 5s delay between update in one client and then reactive update in another one but it doesn't seem to work at all. I even put breakpoints in observe and it is notified immediately. Am I doing something wrong? How does it work?

推荐答案

那10秒应该是10毫秒。

Those 10sec should be 10 ms.


  1. 确保只更新MongoDB而不是Minimongo-例如,如果通过Meteor方法更新,请确保没有客户端存根。

  1. Be sure that you are only updating MongoDB and not Minimongo - for example, if you update through Meteor methods, be sure you don't have client stubs.

尝试以下操作:

Meteor.publish("currentRoom", function (roomName) {
  return Rooms.find({name: roomName}, {
    disableOplog: true,
    pollingThrottleMs: 10000, 
    pollingIntervalMs: 10000
  });
});


您必须禁用oplog拖尾。否则,每次MongoDB日志更改时,您仍然会收到通知。

You have to disable oplog tailing. If you don't, you still get notified every time the MongoDB logs change.

我在客户端上用观察器对其进行了测试,并且它起作用了。

I tested this with an observer on the client and it worked.

Cursor.observe({
  changed: (newdoc, olddoc) => {
    console.log('changed');
  }
});

其他信息:

https://github.com/meteor/docs/ blob / version-NEXT / long-form / oplog-observe-driver.md
http://info.meteor.com/blog/tuning-meteor-mongo-livedata-for-scalability

这篇关于如何使用pollingThrottle和pollingInterval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆