简体   繁体   English

Firebase 实时数据库延迟

[英]Firebase real-time database latency

I am using firebase real-time database for my app.我正在为我的应用程序使用 firebase 实时数据库。 It's great but I am facing a delay of some seconds during writing data from the app to firebase for the very first time.这很棒,但我在第一次将数据从应用程序写入 firebase 时遇到了几秒钟的延迟。 Means every time when I starts the app it takes a time of 2 seconds to send data to firebase.意味着每次启动应用程序时,将数据发送到 firebase 需要 2 秒的时间。 And after that it works fine with great speed.之后,它以极快的速度运行良好。 I know this isn't a big delay by any aspects but in my case I seriously needed the data transfer and fetching instantly.我知道这在任何方面都不是很大的延迟,但就我而言,我非常需要数据传输和立即获取。 Is there any way to reduce this delay?有什么办法可以减少这种延迟? Thanks in advance.提前致谢。

The first time you access the Firebase Realtime Database from your code, the SDK has to establish a connection to the server.第一次从代码访问 Firebase 实时数据库时,SDK 必须建立与服务器的连接。 This involves multiple steps, which are only needed upon establishing the first connection.这涉及多个步骤,仅在建立第一个连接时才需要。 This explains why the first connection may take some time, and indeed it is not uncommon for it to take one of more seconds.这解释了为什么第一次连接可能需要一些时间,而且实际上它需要多几秒钟的情况并不少见。

There is nothing you can do in code to improve the actual connection speed.您无法在代码中做任何事情来提高实际连接速度。 That is up your bandwidth and latency (which I assume you're not interested in changing), and the SDK and server (which you can't change).这增加了您的带宽和延迟(我假设您对更改不感兴趣),以及 SDK 和服务器(您无法更改)。

All you can do is start connecting as early as possible in your app's lifecycle, instead of waiting with it until you need to firs read/write data.您所能做的就是在应用程序的生命周期中尽早开始连接,而不是等到您需要读取/写入数据时才开始连接。 For example, consider adding a listener to .info/connected when your app first starts.例如,考虑在您的应用首次启动时向.info/connected添加一个侦听器。

True, hi vj Shandilya to my knowledge, the initial connection ought to take a tad longer than expected as this was the case while my team and I were working on an IoT based project linked with firebase and Android-Java.真的,嗨 vj Shandilya,据我所知,最初的连接时间应该比预期的要长一点,因为我和我的团队正在开发一个基于 IoT 的项目,该项目与 firebase 和 Android-Java 相关联。

Maybe you can add, a custom (not intense) progress animation to cover up for the 2 sec.也许您可以添加一个自定义(非密集)进度 animation 以掩盖 2 秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM