4

Interesting issue: I've got a MongoDb collection that I'm updating server side, with Meteor client-side hooks into the same collection. I'm noticing ~10 second delays for a mongo-cursor (server side) inserted record to make its way down to the clients.

Here's the rub: If I do the same insert via the Meteor Client (via a Chrome console) the client and all others attached update with sub-second response times.

There's a very large disparity between the server-side insert into Mongo vs. the Client side - somehow the client side inserts are propagated through and pushed out to the other clients much more quickly than if I manually insert documents via the MongoDb shell.

Any ideas on this? I'm sure I'm missing something...

mcauth
  • 924
  • 7
  • 15

1 Answers1

3

The meteor mongo driver polls for changes in Mongo every 10 seconds to ensure that data that's written into it from outside Meteor makes its way down to the client. Here's the relevant source code:

  // every once and a while, poll even if we don't think we're dirty,
  // for eventual consistency with database writes from outside the
  // Meteor universe
  var intervalHandle = Meteor.setInterval(
    _.bind(self._ensurePollIsScheduled, self), 10 * 1000 /* 10 seconds */);
    self._stopCallbacks.push(function () {
    Meteor.clearInterval(intervalHandle);
  });

This behavior is likely to change per Matt Debergalis, one of the core devs:

This polling is so that Meteor will notice DB changes that didn't come through the Meteor server process.

Many apps don't need this, though. We're considering ways to disable it. We also have a more efficient implementation in the hopper.

Community
  • 1
  • 1
TimDog
  • 8,758
  • 5
  • 41
  • 50
  • thanks. Would I be able to observe() my way around this by chance? Looking at the docs I'm wondering if there's a way to coerce it to update more frequently... – mcauth Feb 01 '13 at 02:22
  • There's probably a way to force it in, but honestly I'd either (1) use `DDP` to push the data in or simply (2) wait and see what's `in the hopper` because they're on a pretty rapid release cycle... – TimDog Feb 01 '13 at 02:30
  • DDP is indeed the way to go for me. I'll post a separate question on how that may look - the libraries currently out there seem very new and a bit sparse on examples. Thanks again, that should do it for me. – mcauth Feb 01 '13 at 03:15
  • 1
    Got it working via your suggestions @TimDog, posted the full solution over [here](http://stackoverflow.com/questions/14639700/using-node-ddp-client-to-insert-into-a-meteor-collection-from-node/14654713#14654713). Thanks a ton! – mcauth Feb 01 '13 at 20:51