Calculating Firebase Database Bandwidth

I published an Android application 2 weeks ago called MyPetrol and within three days hit about 90 thousand users in Malaysia. After that, I removed the application due to the huge bandwidth consumption of the Firebase database (117 GB in 3 days). I am a self-taught amateur who is not connected with experience in the field of information technology, so I am really worried about this. Hope someone can help.

The app is a crowd search app for gas prices. The user can enter the price of gas at a certain station, and other users who agree with the specified price may like it. When the price is updated, the counter "how to" reset.

When you open the application, it requests the Google Places API web services for the nearest gas station (maximum 20 stations). At the same time, it intercepts listeners of station data in the Firebase database. The data structure for each station is as follows.

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 track such, there is a data section as

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

I read the use of the Firebase database bandwidth when reading using Query , which we can use (Firebase.getDefaultConfig().setLogLevel(Level.DEBUG))to check traffic, but I have not seen anything about loading and loading bandwidth in logcat. Just 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 requests 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                |
+----------------------------+-----------+-----------+-----------------------------------------+

, , 5,7 . , /prices/placeID, "Station", . "". onPause.

, , . , , Google Place API , , 3 245k . , .

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

. .., . , , .

+----------------------------+-----------+-------+--------------+----------------------------------------------------------+
|           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 |                                                          |
+----------------------------+-----------+-------+--------------+----------------------------------------------------------+

50 , Firebase, -, x10. , :

  • ?
  • Android Device Monitor? - ? ?
  • Firebase ? ? ?

. , - . .

+4
2

. , , . , , .

(1) - . 480kB .

(2) (3). , Firebase, , Android Device Monitor. .

GB , Firebase, . , . :

, , .

0

, . Query Firebase. , .

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

, .indexOn . Firebase . Query . , , :

Firebase Documentation

, .indexOn, Firebase , Firebase , .

, Firebase , Firebase, ! , , , ad-hoc- .

, , , prices. ~ 800 . .indexOn !

+5

Source: https://habr.com/ru/post/1674493/


All Articles