Profile Your Database

Measure the performance of your Firebase Realtime Database with the database profiler tool, built into the Firebase CLI. The profiler tool logs all the activity in your database over a given period of time, then generates a detailed report. Use the detailed report to troubleshoot issues with your database performance, spot problem areas, and reduce unindexed queries.

Build a profile

  1. Before you start profiling your Firebase Realtime Database, make sure you're using the latest version of the Firebase CLI and that you've initialized it for the database and project you want to profile. Note that you must be an editor or owner of that project to profile.

  2. Start profiling your database with the following command:

    firebase database:profile
    The profiler displays a status message as it records operations from your database and builds the profile.

  3. Press Enter to complete the profile and display the results.

Interpret your results

The profiler tool aggregates the data it's collected about your database's operations and displays the results in three primary categories: speed, bandwidth, and unindexed queries.

Speed

The Speed Report measures the server's response time (in milliseconds) for each operation type. However, the speed measured in the Speed Report might not actually reflect the speed end-users experience. Different factors, including network conditions, can add latency on the client side.

The Speed Report includes the following properties:

  • Path: The path in your database where the operations occurred. If there are more than 25 child nodes, the profiler tool collapses these into a parent path and adds a $wildcard marker. You might see your database's root directory in the report, represented by a forward slash /.
  • Count: The number of operations that occurred at the given path.
  • Average Execution Speed: The average time it takes the server to execute business logic needed to handle the particular operation type at that path. The time interval measured here starts after that measured by the "Average Pending Time" described below.
  • Average Pending Time: The average time requests spend queued before getting executed. This delay is common to all client-initiated requests. The total server-side request latency is roughly the sum of that request's pending time and execution speed.
  • Permission Denied: The number of operations at the given path that were blocked by Firebase Database Rules on your database.
Speed Report by Operation Type
Read Execution Speed The server response time for client requests to read data from the database. Read execution time generally scales with the amount of data being read, but even some small reads may also be delayed by cache prefetching.
Write Execution Speed The server response time for client requests to write data to the database. Write execution time scales with the amount of data being written.
Connect Execution Speed The server response time for requests to establish to database clients. Latency for connection requests is dominated by in-memory server-side bookkeeping related to connection management.
Broadcast Execution Speed

The amount of time the server takes to distribute data to clients listening to the given path for realtime updates.

The Count property in the Broadcast Speed Report aggregates the number of broadcasts that happened, not the number of clients that received the information. For example, if 10 clients were listening at a given path, and the server broadcast an update to all 10 clients, the broadcast count only reflects 1 broadcast, even though 10 clients received the data.

The Permission Denied property isn't included in the Broadcast Speed report.

Bandwidth

The Bandwidth Report provides insight on how much data your database consumes across incoming and outgoing operations. You shouldn't use the Bandwidth Report to estimate billing, however, because it doesn't include bandwidth used for other operations, like profiling your database. The Bandwidth Report roughly estimates the payload size of the data consumed by read, write, and broadcast operations to and from your database. It's a tool that measures performance, not one that forecasts billing.

The Bandwidth Report includes the following properties:

  • Path: The path in your database where the operations occurred. If there are more than 25 child nodes, the profiler tool collapses these into a parent path.

  • Total: The total outgoing or incoming bytes used across all operations at the given path.

  • Count: The number of operations that occurred at the given path.

  • Average: The average number of downloaded or uploaded bytes across operations at the given path (bytes/write or bytes/read).

Bandwidth Report
Downloaded Bytes Data consumed through read and broadcast operations sent out via the client SDKs and REST API.
Uploaded Bytes Data consumed through write requests coming into the database server. Deletes show up as writes with 0 bytes under incoming.

Unindexed Queries

Unindexed queries can be expensive, because clients download all of the data at a location and then perform queries on it. This uses up more bandwidth than necessary. Resolve as many unindexed queries as you can to optimize your database's performance.

The Unindexed Queries report displays the following properties:

  • Path: The path in your database where the unindexed queries occurred.
  • Index: The rule you should add to resolve the unindexed queries. Learn more about indexing in Index your data.
  • Count: The number of unindexed queries that occurred at the given path.

Advanced profiling

To see all the operations your database is handling, use the --raw flag when you profile your database, as follows:

firebase database:profile --raw

The raw output also includes client information for each operation, such as userAgent strings and IP addresses. Learn more about the different operations profiled in your Firebase Realtime Database in the operation types section of this page.

The profiler tool: Not a billing tool

Don't use the profiler tool to estimate bandwidth cost. The profiler tool is intended to give you an overall picture of your database's performance, to help you monitor operations and troubleshoot issues, not to estimate billing. It doesn't account for network traffic, it only records an estimate of the application data sent in responses.

The following are some common examples of network traffic billed by Firebase that aren't covered in your database profile:

  • Protocol overhead: Some additional traffic between the server and clients is necessary to establish and maintain a session. Depending on the underlying protocol, this traffic might include: Firebase Realtime Database's realtime protocol overhead, WebSocket overhead, and HTTP header overhead. Each time a connection is established, this overhead, combined with any SSL encryption overhead, contributes to the connection costs. Although this is typically not a large amount of bandwidth, it can be substantial if your payloads are tiny or you make frequent, short connections.
  • SSL encryption overhead: There is a cost associated with the SSL encryption overhead necessary for secure connections. On average, this cost is approximately 3.5KB for the initial handshake, and approximately 40B for TLS record headers on each outgoing message. For most apps, this is a small percentage of your bill. However, this could become a large percentage if your specific case requires a lot of SSL handshakes. For example, devices that don't support TLS session tickets might require large numbers of SSL connection handshakes.

Read more about understanding and estimating your bill.

Profiler command flags and operation types

This section lists the flag options for the firebase database:profile command and describes the operation types that the profiler tool reports.

Flag options

The firebase database:profile command supports the following flag options:

Flag options Description
-h, --help Output usage information.
-o, --output FILENAME Save the output to the specified file.
-i, --input FILENAME Generate the report based on the specified file instead of stream logs from the server.
-d, --duration SECONDS Collect database usage information for the specified number of seconds.
--raw Output the raw stats collected as new-line delimited JSON.

Operation types

The firebase database:profile command reports the following operation types:

concurrent-connect

This operation reflects realtime connections to the database (for example, when a new client connects via an SDK). RESTful connections are not reflected in concurrent-connect operations.

{
    "name": "concurrent-connect",
    "timestamp": 1484776334900
}

concurrent-disconnect

Concurrent-disconnects reflect a connection that has disconnected from the database (for example, when a client disconnects or signs off).

{
    "name": "concurrent-disconnect",
    "timestamp": 1484776341844
}

realtime-write

Write requests from realtime connections. For example, set() and push() operations for web clients. Delete requests are also counted as realtime-write operations, and reflect writes of 0 bytes.

{
    "allowed": true, // If security rules allow the operation
    "bytes": 1,
    "millis": 2,
    "name": "realtime-write",
    "path": [
        "foo"
    ],
    "timestamp": 1484776538763
}

realtime-transaction

This operation type includes transactions conducted through realtime connections. Repeat transactions may be the result of failed attempts and retries.

{
    "allowed": true,
    "bytes": 20,
    "millis": 2,
    "name": "realtime-transaction",
    "path": [
        "foo"
    ],
    "timestamp": 1484776854610
}

realtime-update

These realtime operations for updates reflect overwrites of specific data, not the more general write operations in realtime-write.

{
    "allowed": true,
    "bytes": 5,
    "millis": 2,
    "name": "realtime-update",
    "path": [
        "foo"
    ],
    "timestamp": 1484776538769
}

listener-listen

These operations reflect the initial ask for data at a specific location from a client. For example, the on() or once() methods for web clients.

{
    "allowed": true,
    "bytes": 0,
    "millis": 26,
    "name": "listener-listen",
    "path": [
        "foo"
    ],
    "querySet": [],
    "timestamp": 1484776335024,
    "unIndexed": false
}

listener-broadcast

This operation covers the data sent from the server to any and all clients that are listening at a given location following every write and update operation. The change to the data leads to a broadcast operation. However, you may see 0 updates if there aren't any clients listening.

{
    "bytes": 56, // Total bytes sent across clients
    "clientsUpdated": 3, // This may be 0 if no clients are listening
    "millis": 17,
    "name": "listener-broadcast",
    "path": [
        "baz",
        "mar"
    ],
    "timestamp": 1484775969928
}

listener-unlisten

These operations reflect listening clients that sign off or stop listening through the detach methods (for example, off() for web, or removeAllObservers for iOS).

{
    "name": "listener-unlisten",
    "path": [
        "foo"
    ],
    "timestamp": 1484776335044
}

rest-read

GET requests through the REST API.

{
    "allowed": true,
    "bytes": 348, // This would be 0 if the read data was null
    "millis": 26,
    "name": "rest-read",
    "path": [],
    "querySet": [
        {
            "default": true,
            "endIndexValue": "[MAX_NAME]",
            "equality": false,
            "index": {},
            "limit": null,
            "range": false,
            "simpleLimit": false,
            "startIndexValue": "[MIN_NAME]",
            "viewFrom": null
        }
    ],
    "timestamp": 1484775747416
}

rest-write

PUT and POST requests through the REST API. DELETE requests reflect rest-write operations of 0 bytes.

{
    "allowed": true,
    "bytes": 13,
    "millis": 116,
    "name": "rest-write",
    "path": [],
    "timestamp": 1484775917216
}

rest-transaction

For transaction-like behavior, use conditional Requests. The rest-transaction operation captures requests using Etag or if-match headers.

{
    "allowed": true,
    "bytes": 13,
    "millis": 116,
    "name": "rest-transaction",
    "path": [],
    "timestamp": 1484775917216
}

rest-update

Updates through the REST API reflect PATCH requests.

{
    "allowed": true,
    "bytes": 5,
    "millis": 11,
    "name": "rest-update",
    "path": [
        "baz",
        "mar"
    ],
    "timestamp": 1484775969930
}

on-disconnect-put

These operations reflect the addition of onDisconnect listeners to write operations. For example, when you use onDisconnect().setValue().

{
    "allowed": true,
    "bytes": 4,
    "millis": 2,
    "name": "on-disconnect-put",
    "path": [
        "baz",
        "mar"
    ],
    "timestamp": 1484775969930
}

on-disconnect-update

These operations reflect the addition of onDisconnect listeners to update operations. For example, when you use onDisconnect().updateChildren().

{
    "allowed": true,
    "bytes": 4,
    "millis": 2,
    "name": "on-disconnect-update",
    "path": [
        "baz",
        "mar"
    ],
    "timestamp": 1484775969930
}

on-disconnect-cancel

These operations reflect the removal of onDisconnect listeners. For example, when you use onDisconnect().set().cancel().

{
    "millis": 2,
    "name": "on-disconnect-cancel",
    "path": [
        "baz",
        "mar"
    ],
    "timestamp": 1484775969930
}

run-on-disconnect

These operations reflect the triggering of onDisconnect listeners. When a realtime client disconnects after adding at least one onDisconnect listener, the profiler records a single run-on-disconnect operation to reflect the aggregated bytes and time of all the onDisconnect listeners triggered.

{
    "bytes": 4,
    "millis": 2,
    "name": "run-on-disconnect",
    "timestamp": 1484775969930
}