【问题标题】:How insure indexing every object with Firebase FlashLight in a ElasticSearch Bonsai Free Instance如何确保在 ElasticSearch Bonsai 免费实例中使用 Firebase FlashLight 索引每个对象
【发布时间】:2016-09-24 05:05:27
【问题描述】:

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

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

未能索引 firebase/xxx/-KHLhdwGplb3lHWjm8RS:错误:超出并发请求限制。请考虑批量处理您的请求,或联系 support@bonsai.io 寻求帮助。

如何解决?

【问题讨论】:

    标签: node.js elasticsearch concurrency firebase


    【解决方案1】:

    如果您有一堆数据要索引,Flashlight 应用程序将要求 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));
            });
        },
        ...
    }
    

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

    【讨论】:

    • @Anthony : 我做了你的建议,我仍然有同样的错误
    猜你喜欢
    • 1970-01-01
    • 2017-10-06
    • 2017-02-04
    • 1970-01-01
    • 2020-01-09
    • 2015-08-18
    • 2017-03-14
    • 1970-01-01
    • 2021-05-10
    相关资源
    最近更新 更多