Firebase 数据库下载使用中是否包含 HTTPS 握手数据?
Is HTTPS Handshake Data Included in Firebase Database Download Usage?
我一直在制作一个应用程序的原型,该应用程序报告不常发生的设备生成的事件(例如地理围栏转换)和用户对云功能的请求。数据库触发器似乎是一种安全、简单且低成本的调用云功能的方法。该应用程序将 event/request 参数打包成一个小对象(<500 字节)并将该对象写入 Firebase 数据库,从而触发所需的云功能。这很好用并提供了预期的好处。
当我扩大测试规模并查看 Firebase 控制台的数据库使用面板时,我发现下载数据的大小比我预期的要大得多。我的客户端代码没有监听器;它只写数据。我检查过云函数只读取预期的小对象,代码中的单个查询是针对具有安全规则中指定索引的数据。
然后我开始查看 Android Device Monitor 为特定客户端事件提供的网络统计信息。数据显示,当数据库连接不存在且需要建立以写入服务器时,大约会收到 4500 字节的数据。由于对 HTTPS 知之甚少,我假设这是与数据库连接相关的 Firebase 开销,并考虑了其他选项。
接下来,我尝试使用我自己的 OkHttpClient 连接到 REST API 来编写触发器对象。当我看到为写入一个 500 字节的对象而接收到相同的 4000 多个字节时,我意识到接收到的数据必须是证书和密钥的 HTTPS 握手并且可能是不可避免的。
我的问题是:
- 当与 Firebase 数据库服务器建立连接时,客户端收到的 4000 多个字节主要是 HTTPS 连接的安全数据交换吗?
- 这些字节是否被视为 "downloaded data" 并因此包含在 Firebase 控制台和计费计算中显示的使用总量中?
- 如果云函数使用
admin.database()
访问 Firebase 数据库,该 SDK 是否使用 REST API 实现?在那种情况下,问题 #2 中的问题是否也适用于此?
正如我在 post 开头指出的那样,我处理的 events/user-requests 并不常见。几乎总是这样,当需要写入数据来报告事件时,数据库连接将不存在,需要建立。如果问题 #2 的答案是肯定的,那么原本认为小于 500 字节的操作的成本实际上将超过 4000 字节。对于这个用例,向云函数报告事件的成本最低的方法似乎是使用 HTTP triggers,而不是数据库触发器。
更新:
如果我更彻底地搜索文档,我就不需要 post 这个问题了。 Database Billing and Profiler documentation:
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.
你的问题中有很多项目细节,Stack Overflow 可能不是最好的答案。我将在下面提供一些简单的答案,但建议您 reach out to Firebase support 在故障排除方面获得个性化帮助。
HTTPS 握手带宽是计费流量,应显示在 Firebase 控制台的数据库使用面板中。我不知道开销是多少。
Admin SDK for Node 使用套接字连接到 Firebase 数据库。它不使用 REST API。协商 HTTPS/WebSocket 连接时的带宽也是此处的计费流量。
在创建新容器时会建立从 Cloud Functions 到数据库的连接。这可以在项目功能的首次部署时,在 activity 一段时间后,或者由于高 activity.
而需要扩展 Cloud Functions 时
我一直在制作一个应用程序的原型,该应用程序报告不常发生的设备生成的事件(例如地理围栏转换)和用户对云功能的请求。数据库触发器似乎是一种安全、简单且低成本的调用云功能的方法。该应用程序将 event/request 参数打包成一个小对象(<500 字节)并将该对象写入 Firebase 数据库,从而触发所需的云功能。这很好用并提供了预期的好处。
当我扩大测试规模并查看 Firebase 控制台的数据库使用面板时,我发现下载数据的大小比我预期的要大得多。我的客户端代码没有监听器;它只写数据。我检查过云函数只读取预期的小对象,代码中的单个查询是针对具有安全规则中指定索引的数据。
然后我开始查看 Android Device Monitor 为特定客户端事件提供的网络统计信息。数据显示,当数据库连接不存在且需要建立以写入服务器时,大约会收到 4500 字节的数据。由于对 HTTPS 知之甚少,我假设这是与数据库连接相关的 Firebase 开销,并考虑了其他选项。
接下来,我尝试使用我自己的 OkHttpClient 连接到 REST API 来编写触发器对象。当我看到为写入一个 500 字节的对象而接收到相同的 4000 多个字节时,我意识到接收到的数据必须是证书和密钥的 HTTPS 握手并且可能是不可避免的。
我的问题是:
- 当与 Firebase 数据库服务器建立连接时,客户端收到的 4000 多个字节主要是 HTTPS 连接的安全数据交换吗?
- 这些字节是否被视为 "downloaded data" 并因此包含在 Firebase 控制台和计费计算中显示的使用总量中?
- 如果云函数使用
admin.database()
访问 Firebase 数据库,该 SDK 是否使用 REST API 实现?在那种情况下,问题 #2 中的问题是否也适用于此?
正如我在 post 开头指出的那样,我处理的 events/user-requests 并不常见。几乎总是这样,当需要写入数据来报告事件时,数据库连接将不存在,需要建立。如果问题 #2 的答案是肯定的,那么原本认为小于 500 字节的操作的成本实际上将超过 4000 字节。对于这个用例,向云函数报告事件的成本最低的方法似乎是使用 HTTP triggers,而不是数据库触发器。
更新:
如果我更彻底地搜索文档,我就不需要 post 这个问题了。 Database Billing and Profiler documentation:
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.
你的问题中有很多项目细节,Stack Overflow 可能不是最好的答案。我将在下面提供一些简单的答案,但建议您 reach out to Firebase support 在故障排除方面获得个性化帮助。
HTTPS 握手带宽是计费流量,应显示在 Firebase 控制台的数据库使用面板中。我不知道开销是多少。
Admin SDK for Node 使用套接字连接到 Firebase 数据库。它不使用 REST API。协商 HTTPS/WebSocket 连接时的带宽也是此处的计费流量。
在创建新容器时会建立从 Cloud Functions 到数据库的连接。这可以在项目功能的首次部署时,在 activity 一段时间后,或者由于高 activity.
而需要扩展 Cloud Functions 时