【发布时间】: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