【问题标题】:Reading Cloud Bigtable from Cloud Functions using Node.js takes > 1500ms使用 Node.js 从 Cloud Functions 读取 Cloud Bigtable 需要 > 1500 毫秒
【发布时间】:2019-10-22 17:18:54
【问题描述】:

我正在尝试使用 Node.JS 通过 Google Cloud Functions 读取 Cloud Bigtable 密钥,并且我能够读取它,但 Cloud Function 执行时间超过 1500 毫秒。

我听说 Cloud Bigtable 在数据检索方面非常快,但在这种情况下并没有发生。

有人可以帮我解决我在这里做错了吗?

我尝试全局加载 Bigtable 库和对象:

/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */

// Imports the Google Cloud client library
const Bigtable = require('@google-cloud/bigtable');

const TABLE_ID = '';
const COLUMN_FAMILY_ID = '';
const COLUMN_QUALIFIER = '';
const INSTANCE_ID = '';

// Creates a Bigtable client
const bigtable = new Bigtable();

// Connect to an existing instance:my-bigtable-instance
const instance = bigtable.instance(INSTANCE_ID);

// Connect to an existing table:my-table
const table = instance.table(TABLE_ID);

const filter = [{
  family: COLUMN_FAMILY_ID,
}, {
  column: COLUMN_QUALIFIER
}];

exports.helloWorld = (req, res) => {

    console.log("started");

    (async () => {
        try {

          var query_params = req.query;
          var rowkey = query_params.key;

          console.log("before query");

          const [singleRow] = await table.row(rowkey).get({filter});

          console.log("after query");

          res.status(200).send();

        } catch (err) {
            // Handle error performing the read operation
            console.error(`Error reading rows :`, err);
        }
    })();

};

我把控制台日志放在不同的点,查询前后的日志时间有1500ms左右的差距。

【问题讨论】:

    标签: google-cloud-functions google-cloud-bigtable


    【解决方案1】:

    根据documentation

    要从 Cloud Bigtable 获得良好的性能,必须设计一个架构,以便在每个表中均匀分配读取和写入。

    意思是,Bigtable 的性能在很大程度上取决于架构设计等,例如工作负载、每行单元、每个集群的节点、磁盘等。不仅是访问它的环境(使用您的代码,我访问了我的示例 Bigtable 表GCF 为 750 毫秒,Shell 为 4000 毫秒)。

    另外,如果您想正确测试 Bigtable 的性能,建议在适当的情况下进行:

    1. 使用生产实例。开发实例不会给你 准确了解生产实例在负载下的表现。

    2. 使用至少 300 GB 的数据。 Cloud Bigtable 在 1 TB 时表现最佳 或更多数据。但是,300 GB 的数据足以提供 在 3 节点集群上的性能测试中得到了合理的结果。在 更大的集群,每个节点至少使用 100 GB 的数据。

    3. 保持低于建议的每个节点的存储利用率。为了 详细信息,请参阅每个节点的存储利用率。

    4. 在测试之前,请运行几分钟的大量预测试。这一步 让 Cloud Bigtable 有机会在您的节点之间平衡数据 基于它观察到的访问模式。

    5. 运行测试至少 10 分钟。这一步让 Cloud Bigtable 进一步优化您的数据,它有助于确保您将测试 从磁盘读取以及从内存中缓存读取。

    【讨论】:

    • 感谢马克西姆提供的详细信息 :)
    猜你喜欢
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 2020-04-01
    • 1970-01-01
    • 2018-01-14
    • 2016-05-26
    • 2018-12-22
    相关资源
    最近更新 更多