Firebase数据库带宽计算 [英] Firebase Database Bandwidth Calculation

查看:231
本文介绍了Firebase数据库带宽计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在2周前发布了一个名为MyPetrol的Android应用程序,并在三天内在马来西亚大约有9万用户。之后,由于Firebase数据库带宽消耗巨大(3天117GB),我取下了应用程序。我是一个自学成才的业余爱好者,不是来自IT相关的背景,所以我很困扰这个。希望有人可以帮忙。

该应用程序是一个汽油价格的众包应用程序。用户可以在一个特定的站点输入汽油的价格,并且同意所述价格的其他用户可以喜欢它。一旦价格更新,喜欢的计数将被重置。



打开应用程序后,它会查询Google Places API Web服务查询附近的加油站(最多20个工作站) 。因此,它会将收听者与Firebase数据库中的电台数据相关联。每个电台的数据结构如下所示。

 价格{
ChIJpXJ4phI4zDERJqFTBzawpXk = {
placeID ='
company = 500,
lat = 3.2095573, ',
userName ='xxx',
time = 1491833181946,
ron95 = 2.0,
ron97 = 1.7,
diesel = 2.0,
isValid =真正的


$ / code $ / pre

为了跟踪喜欢,部分数据为

pre $喜欢{
ChIJpXJ4phI4zDERJqFTBzawpXk = {
firebaseID1 = true,
firebaseID2 = true,
firebaseID3 = true
}
}

I阅读 Firebase数据库带宽在使用Query阅读时使用圣人,我们可以使用(Firebase.getDefaultConfig()。setLogLevel(Level.DEBUG))来进行流量检查,但是我没有看到任何有关在logcat中上传和下载带宽。只有这样...

  04-10 22:39:19.250 3015-3192 /? D / RepoOperation:onDataUpdate:/ prices / ChIJpXJ4phI4zDERJqFTBzawpXk 
04-10 22:39:19.250 3015-3192 /? D / RepoOperation:onDataUpdate:/ prices / ChIJpXJ4phI4zDERJqFTBzawpXk {time = 1491833181946,firebaseID = xxx,valid = true,diesel = 2,ron97 = 1.7000000476837158,ron95 = 2,placeID = ChIJpXJ4phI4zDERJqFTBzawpXk,name = Shell Malaysia(Iznora Enterprise) xxx,company = 500,lat = 3.2095573,lng = 101.7185698}
04-10 22:39:19.268 3015-3015 /? D / EventRaiser:提高/价格/价格:{time = 1491833181946,firebaseID = xxx,valid = true,diesel = 2,ron97 = 1.7000000476837158,ron95 = 2,placeID = ChIJpXJ4phI4zDERJqFTBzawpXk,name = Shell Malaysia(Iznora Enterprise), userName = xxx,company = 500,lat = 3.2095573,lng = 101.7185698}
04-10 22:39:19.273 3015-3015 /? D / EventRaiser:Raising / likes / ChIJpXJ4phI4zDERJqFTBzawpXk:VALUE:null

监视以检查每个操作的流量。以下是Firebase的平均结果。谷歌地图和其他http查询不包括在内。

  + --------------- ------------- ----------- + + ----------- ------------ + ----------------------------- + 
|行动| Rx(字节)| Tx(字节)|注意|
+ ---------------------------- + ----------- + ---- ------- + ----------------------------------------- +
| onPause | 2942 | 4680 |分离所有听众|
| onResume | 10143 | 5204 |重新连接15个站点的所有听众|
|点击自己来like 620 | 535 |编写动作+下载/喜欢/ placeID |
|通过自我更新价格| 1642 | 1783 |写行动+下载/地方/ placeID |
|点击其他用户的like 382 | 112 |下载/ likes / placeID |
|更新其他用户的价格| 423 | 104 |下载/放置/ placeID |
+ ---------------------------- + ----------- + ---- ------- + ----------------------------------------- +

就在我将应用程序关闭之前,数据库中有5.7MB的数据。我可以保证我把每个电台的听众直接连接到/ prices / placeID,所以我没有检索到整个电台的数据,而只是检索那个特定电台的数据。同样的喜欢。监听器也在onPause上分离。



我没有可用的用户操作日志,因此我很难追溯发生的事情。然而,每当用户打开应用程序,必须查询Google Place API,所以我知道在3天内,我有245k的查询。因此,每个用户会话。

  117GB / 245k session =〜480kB / session 

这似乎很大。我没有带宽等经验,所以我可能是错的。即使我假设所有的用户在下面做了极不可能的动作,我仍然无法填满带宽。

  +  - --------------------------- + ----------- + ------- +  - ------------ + ------------------------------------- --------------------- + 
|行动| Rx(字节)|时间|总计(字节)|注意|
+ ---------------------------- + ----------- + ---- --- + -------------- + ------------------------------- --------------------------- +
| onPause | 2942 | 10 | 29420 |暂停和恢复10次,这不会更新地图。 |
| onResume | 10143 | 10 | 101430 | |
|点击自己来like 620 | 15 | 9300 |点击所有15个站|
|通过自我更新价格| 1642 | 15 | 24630 |更新所有15个站的价格|
|点击其他用户的like 382 | 100 | 38200 |每个会话点击100个其他用户|
|更新其他用户的价格| 423 | 100 | 42300 |其他100位用户更新了每个会话的价格|
|总计| | | 245280 | |
+ ---------------------------- + ----------- + ---- --- + -------------- + ------------------------------- --------------------------- +

对于普通用户,我认为每个会话最多只有50kB左右,所以Firebase似乎消耗了10倍的带宽。所以我的问题:


  1. 我是否对每个会话的带宽进行计算?
  2. 是使用Android Device Monitor确定的流量是否正确?我错过了什么吗?有没有更好的方法来检查?

  3. Firebase如何计算带宽?它是否包含上传?有没有隐藏的带宽?

很抱歉,感谢有人能帮忙。
谢谢。

解决方案

我发现了这个错误。这与上述问题完全无关,但我在这里记录下来帮助其他用户。所以首先回答我自己的问题。



问题(1) - 是的。问题(2)和(3) - Firebase消耗的带宽应低于Android设备监控器记录的带宽。我联系了支持团队,并得到了以下回复。


对于您的带宽问题,下载的GB只测量发送的数据量Firebase数据库到您的客户端应用程序。这意味着将数据检索到您的应用程序中。您可能需要查看以下链接以获取更多信息:




<因此,扣除一些开销,实际的带宽应该略低。

I've published an android app 2 weeks ago called MyPetrol and within three days hit roughly 90k users in Malaysia. After that, I took down the app due to huge Firebase Database bandwidth consumption (117GB for the 3 days). I'm a self-taught hobbyist who do not come from IT related background, so I'm really troubled by this. Hope that someone can help.

The app is a crowd-sourcing app for petrol price. User can enter the price of petrol at a particular station and other users who agree with the stated price can "like" it. Once a price is updated, the "like" count is reset.

Upon opening the app, it queries Google Places API Web Services for nearby petrol station (max 20 stations). With that, it hooks listeners to the stations' data in Firebase Database. The data structure for each station looks like this.

prices{
    ChIJpXJ4phI4zDERJqFTBzawpXk={
        placeID='ChIJpXJ4phI4zDERJqFTBzawpXk',
        company=500,
        lat=3.2095573,
        lng=101.7185698,
        name='Shell Malaysia (Iznora Enterprise)',
        firebaseID='xxx',
        userName='xxx',
        time=1491833181946,
        ron95=2.0,
        ron97=1.7,
        diesel=2.0,
        isValid=true
    }
}

To keep track of the likes, there is a section of data as

likes{
    ChIJpXJ4phI4zDERJqFTBzawpXk={
        firebaseID1=true,
        firebaseID2=true,
        firebaseID3=true
    }
}

I read Firebase database bandwidth usage when read with Query that we can use (Firebase.getDefaultConfig().setLogLevel(Level.DEBUG)) for traffic check, but I didn't see anything regarding the upload and download bandwidth in logcat. Only something like this...

04-10 22:39:19.250 3015-3192/? D/RepoOperation: onDataUpdate: /prices/ChIJpXJ4phI4zDERJqFTBzawpXk
04-10 22:39:19.250 3015-3192/? D/RepoOperation: onDataUpdate: /prices/ChIJpXJ4phI4zDERJqFTBzawpXk {time=1491833181946, firebaseID=xxx, valid=true, diesel=2, ron97=1.7000000476837158, ron95=2, placeID=ChIJpXJ4phI4zDERJqFTBzawpXk, name=Shell Malaysia (Iznora Enterprise), userName=xxx, company=500, lat=3.2095573, lng=101.7185698}
04-10 22:39:19.268 3015-3015/? D/EventRaiser: Raising /prices/ChIJpXJ4phI4zDERJqFTBzawpXk: VALUE: {time=1491833181946, firebaseID=xxx, valid=true, diesel=2, ron97=1.7000000476837158, ron95=2, placeID=ChIJpXJ4phI4zDERJqFTBzawpXk, name=Shell Malaysia (Iznora Enterprise), userName=xxx, company=500, lat=3.2095573, lng=101.7185698}
04-10 22:39:19.273 3015-3015/? D/EventRaiser: Raising /likes/ChIJpXJ4phI4zDERJqFTBzawpXk: VALUE: null

In the end, I used Android Device Monitor to check the traffic for each action. Below are the average results for Firebase only. Google Map and other http queries are not included.

+----------------------------+-----------+-----------+-----------------------------------------+
|           Action           | Rx(bytes) | Tx(bytes) |                  Notes                  |
+----------------------------+-----------+-----------+-----------------------------------------+
| onPause                    |      2942 |      4680 | detach all listeners                    |
| onResume                   |     10143 |      5204 | reattach all listeners for 15 stations  |
| click "like" by self       |       620 |       535 | write action + download /likes/placeID  |
| update price by self       |      1642 |      1783 | write action + download /places/placeID |
| click "like" by other user |       382 |       112 | download /likes/placeID                 |
| update price by other user |       423 |       104 | download /places/placeID                |
+----------------------------+-----------+-----------+-----------------------------------------+

Right before I took the app down, I had 5.7MB of data in the database. I can guarantee that I hooked up the listener directly for each station as /prices/placeID, so I did not retrieve the whole "Station" data, but only data for that specific station. Similarly for the "like". The listeners are also detached onPause.

I do not have any log of user actions available, hence it is difficult for me to trace back what happened. However, whenever the users open the app, Google Place API must be queried, so I know that during the 3 days, I had 245k queries. Thus for each user session.

117GB / 245k session = ~480kB/session

That seems huge. I have zero experience with bandwidth etc, so I might be wrong. Even if I assume that all users did the extremely unlikely action below, I still can't fill up the bandwidth.

+----------------------------+-----------+-------+--------------+----------------------------------------------------------+
|           Action           | Rx(bytes) | Times | Total(bytes) |                          Notes                           |
+----------------------------+-----------+-------+--------------+----------------------------------------------------------+
| onPause                    |      2942 |    10 |        29420 | Pause and resume 10 times, this does not update the map. |
| onResume                   |     10143 |    10 |       101430 |                                                          |
| click "like" by self       |       620 |    15 |         9300 | Click like on all 15 stations                            |
| update price by self       |      1642 |    15 |        24630 | Update price on all 15 stations                          |
| click "like" by other user |       382 |   100 |        38200 | 100 other users clicked per session                      |
| update price by other user |       423 |   100 |        42300 | 100 other users updated the price per session            |
| Total                      |           |       |       245280 |                                                          |
+----------------------------+-----------+-------+--------------+----------------------------------------------------------+

For a normal user, I'd expect to have around 50kB max per session only, so Firebase seems to be consuming x10 amount of bandwidth. So my questions:

  1. Did I do the calculation right for bandwidth per session?
  2. Is the traffic determined using Android Device Monitor correct? Am I missing something? Is there a better way to check?
  3. How does Firebase calculate the bandwidth? Does it include uploads as well? Is there any hidden bandwidth?

Sorry for the long post. Appreciate if someone can help. Thank you.

解决方案

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.

这篇关于Firebase数据库带宽计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆