How to use pollingThrottle and pollingInterval?

2019-05-21 14:59发布

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 Number (Server only) How often to poll this query when observing on the server. In milliseconds. Defaults to 10 seconds.

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.

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
    });
});

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?

1条回答
Deceive 欺骗
2楼-- · 2019-05-21 15:25

Those 10sec should be 10 ms.

  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.

  2. Try this:

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

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');
  }
});

Additional info:

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

查看更多
登录 后发表回答