node.js - 如何确保在 ElasticSearch Bonsai 免费实例中使用 Firebase FlashLight 索引每个对象

标签 node.js elasticsearch concurrency firebase

感谢手电筒的教程https://github.com/firebase/flashlight , 这在某种程度上很容易用 Firebase 进行全文搜索。

但是,如果您保留免费的 ES 实例,它会在并发访问方面受到限制,当您启动 Node 应用程序时,您会在日志中看到以下消息:

failed to index firebase/xxx/-KHLhdwGplb3lHWjm8RS: Error: Concurrent request limit exceeded. Please consider batching your requests, or contact support@bonsai.io for help.

如何解决?

最佳答案

如果你有一堆数据要索引,手电筒应用程序会要求 ES 即时索引每个对象,没有任何资源访问限制。您必须使用信号量控制/限制对共享资源的访问。

安装信号量库

npm i --save semaphore

编辑PathMonitor.js文件,将ES资源的访问限制为1

PathMonitor.prototype = {
    _init: function () {
        this.sem = require('semaphore')(1);
        this.addMonitor = this.ref.on('child_added', this._process.bind(this, this._childAdded));
        this.changeMonitor = this.ref.on('child_changed', this._process.bind(this, this._childChanged));
        this.removeMonitor = this.ref.on('child_removed', this._process.bind(this, this._childRemoved));
    },
    ...
    _index: function (key, data, callback) {
        var that = this;
        that.sem.take(function () {
            that.esc.index({
                index: that.index,
                type : that.type,
                id   : key,
                body : data
            }, function (error, response) {
                that.sem.leave();
                if (callback) {
                    callback(error, response);
                }
            }.bind(that));
        });
    },
    ...
}

如果是付费计划,则可能不需要。

关于node.js - 如何确保在 ElasticSearch Bonsai 免费实例中使用 Firebase FlashLight 索引每个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37456690/

相关文章:

node.js - 如何在 node.js 中要求一个类

javascript - 在 PassportJS 中生成自定义错误

c++ - 如何通过调用类中的函数来创建线程?

java - Elastic Search SSL证书到期

php - 在 PHP 中转义 elasticsearch 特殊字符

java - 库存控制的并发控制

Node.js 并行运行两个函数

node.js - mongoDB - 使用 node.js 在多个字段中进行文本搜索

javascript - node.js 中的几个控制台实例

python - 将从 scrapy 中抓取的数据放入 elasticsearch 时出现 TypeError