Firebase Database Bandwidth Calculation

坚强是说给别人听的谎言 提交于 2019-12-02 19:43:46
tingyik90

So, back to the high bandwidth consumption. It has to do with Query of Firebase Database. I have a query below when new user sign up.

Query priceQuery = getPricesRef().orderByChild("firebaseID").equalTo(myFirebaseID);

This was the beginning of my nightmare beause I did not set .indexOn for that database. Read the official Firebase documentation here. The documentation regarding Query is very poor. It only states that performance will be poor without index, but never mention about the bandwidth:

Based on the statement above, my assumption was that without .indexOn, a query to Firebase may take longer to reply, since Firebase server may take longer to provide the search result.

However, as answered in Firebase database bandwidth usage when read with Query, the whole database is downloaded first from Firebase and then sorted and queried on Client's side! I guess that's what they meant by realtime client libraries can execute ad-hoc queries without specifying indexes.

As my database grows, each user sign up begins to consume higher bandwidth by downloading the whole prices database. Towards the end, it was consuming ~800kB per user for just signing up. So make sure to use .indexOn always!

I found the bug. It is completely unrelated to the above question, but I'm documenting it here to help other users. So first, to answer my own questions.

Question (1) - Yes. That estimate of 480kB per session should be quite accurate.

Question (2) and (3) - The bandwidth consumed by Firebase should be lower than those recorded by Android Device Monitor. I contacted the support team and got the following reply.

For your bandwidth questions, the GB downloaded only measures the amount of data being sent by the Firebase database to your client app. This means data retrieval to your application.You might want to check the following links for more information:

Hence, deducting some overhead, the actual bandwidth should be slightly lower.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!