gpt4 book ai didi

java - 为什么我的 Cloud Run - 到 Firebase 调用需要这么长时间?

转载 作者:行者123 更新时间:2023-12-01 17:42:42 30 4
gpt4 key购买 nike

我一直在尝试从 Cloud Run 中运行的 Java 应用程序连接到 Firebase 数据库。我的应用的 Firebase 事务的执行似乎有很多分钟的延迟(即使如此,我也没有得到所需的结果)。

当我的应用程序启动时,将调用以下方法:

    public void init() throws Exception {
LOGGER.info("FirebaseRepo-init starting...");

FileInputStream serviceAccount =
new FileInputStream("/MyDatabase.json");

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://mydatabase-222123.firebaseio.com")
.build();

LOGGER.info("FirebaseRepo-init 1");

fbApp = FirebaseApp.initializeApp(options);

LOGGER.info("FirebaseRepo-init 2");

dbRef = FirebaseDatabase.getInstance().getReference();

LOGGER.info("FirebaseRepo-init 3");

final DatabaseReference entityRef = dbRef.child("entities");

LOGGER.info("FirebaseRepo-init 4");

Entity e = testEntity();

entityRef.runTransaction(new Transaction.Handler() {

@Override
public void onComplete(DatabaseError error, boolean committed, DataSnapshot currentData) {
LOGGER.info("FirebaseRepo-init tx onComplete; com=" + committed + "; err=" + error);
}

@Override
public Result doTransaction(MutableData data) {
LOGGER.info("FirebaseRepo-init tx start");
MutableData childData = data.child(e.getGuid().toString());
if (childData != null) {
LOGGER.info("FirebaseRepo-init tx progress");
childData.setValue(e);
} else {
LOGGER.info("FirebaseRepo-init tx null child");
}
LOGGER.info("FirebaseRepo-init tx will return");
return Transaction.success(data);
}
});

LOGGER.info("...FirebaseRepo-init ending");
}

部署应用后检查日志,我们看到:

2020-03-30T01:51:40.318532ZINFO: FirebaseRepo-init starting...
2020-03-30T01:51:40.749160ZINFO: FirebaseRepo-init 1
2020-03-30T01:51:40.781135ZINFO: FirebaseRepo-init 2
2020-03-30T01:51:40.947959ZINFO: FirebaseRepo-init 3
2020-03-30T01:51:40.949045ZINFO: FirebaseRepo-init 4
2020-03-30T01:51:40.952295ZINFO: ...FirebaseRepo-init ending
2020-03-30T01:54:10.647748ZINFO: FirebaseRepo-init tx start
2020-03-30T01:54:10.945862ZINFO: FirebaseRepo-init tx progress
2020-03-30T01:54:12.546400ZINFO: FirebaseRepo-init tx will return
2020-03-30T01:56:03.046096ZINFO: FirebaseRepo-init tx start
2020-03-30T01:56:03.245789ZINFO: FirebaseRepo-init tx progress
2020-03-30T01:56:03.547215ZINFO: FirebaseRepo-init tx will return
2020-03-30T01:56:10.446070ZINFO: FirebaseRepo-init tx onComplete; com=true; err=null

该事务在应用程序启动后大约两分半钟被调用...然后大约五分钟后再次调用,最后完成。此外,当我转到 Firebase 仪表板时,我在数据库中看不到任何内容;尽管我没有看到任何错误报告,但没有添加任何内容。

对我所犯的 n00b 错误有什么想法吗?

最佳答案

考虑到问题中的评论,Cloud Run 似乎确实按预期工作,但是,Cloud Run 可能不是此特定用例的推荐产品。根据Doug的回答Cloud Run isn't meant to run arbitrary code on deployment. It's meant to run code in response to incoming HTTP requests as your run a web server on port 8080. ,这对于所面临的延迟来说是有意义的。可能值得检查其他产品。

关于java - 为什么我的 Cloud Run - 到 Firebase 调用需要这么长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60923113/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com