Dan P.
Dan P.

Reputation: 1775

Understand where the bandwidth usage is coming from in Firebase database

My app is growing in terms of bandwidth usage with Firebase database and I am trying to optimize my queries to use less bandwidth (thus reduce cost) but I am doing this quite blindly because there are no statistics about my database usage (I can't know what queries take the most bandwidth).

Is there somehow a way to know which queries are taking a lot of bandwidth? How do you go about optimizing usage with Firebase database?

Edit:

I have a chat website, and I use observers such as messagesRef.child(conversationID).limitToLast(25).on('child_‌​added'... conversationsRef.child(conversationID).('participants').on('value'...

Upvotes: 10

Views: 3081

Answers (4)

Dan P.
Dan P.

Reputation: 1775

The Firebase Profiler saved my life for this. https://firebase.google.com/docs/database/usage/profile

Was able to pinpoint exactly what reference (including children) was hogging the bandwidth, which made it much easier to figure out which part of the code is problematic.

Upvotes: 5

devprashant
devprashant

Reputation: 1293

highly agreed with ZagNut answer.

Logging queries completion on "then()" will help you here.

You can keep count of queries for a node request on client side and save that request count by client id in a separate node from your data structure on firebase database.

Now filter these queries to find usage patterns.

Thanks.

Upvotes: 0

LiorK
LiorK

Reputation: 1680

Just in case you are not already using Firebase's .indexOn()... which is the best way to improve your performance (so they say hereunder), take a look at Index Your Data. Firebase guys say:

If you know in advance what your indexes will be, you can define them via the .indexOn rule in your Firebase Realtime Database Rules to improve query performance.

Upvotes: 0

ZagNut
ZagNut

Reputation: 1451

there's no query tuning tools, if that's what you're looking for. you could build in simple time logging to capture just before and after queries are issued, log that data, and harvest it from client to narrow down to the most poorly performing ones.

hard to help without seeing the actual queries or the data model.

Upvotes: 3

Related Questions