流星:服务器端数据库插入延迟 [英] Meteor: server-side db insert delays

查看:36
本文介绍了流星:服务器端数据库插入延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有趣的问题:我有一个正在更新服务器端的 MongoDb 集合,Meteor 客户端挂钩到同一个集合中.我注意到 mongo-cursor(服务器端)插入的记录延迟了大约 10 秒才能到达客户端.

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.

问题在于:如果我通过 Meteor 客户端(通过 Chrome 控制台)执行相同的插入,则客户端和所有其他附加更新的响应时间为亚秒级.

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.

服务器端插入 Mongo 与客户端之间存在很大差异 - 不知何故,客户端插入传播并推送到其他客户端比我更快通过 MongoDb shell 手动插入文档.

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...

推荐答案

meteor mongo 驱动程序每 10 秒轮询一次 Mongo 中的更改,以确保从 Meteor 外部写入的数据通过到客户端.这是相关的源代码:

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

这种行为可能会改变 核心开发者之一马特·德贝加利斯 (Matt Debergalis):

此轮询是为了让 Meteor 注意到并非通过 Meteor 服务器进程的数据库更改.

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.

这篇关于流星:服务器端数据库插入延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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