计算Firebase消息大小 [英] Computing firebase message size
问题描述
我注意到运行时,实时数据库计算器是显示大于预期的数据大小。为了验证这一点,我开始了一个玩具应用程序,它有一个名为测试与数据的裁判:
{foo :bar}
回到其他答案,我估计这个数据是在20个字节以下。
使用以下代码检索数据:
firebase.database ).ref(test)。once(value,function(snapshot){
console.log(snapshot.val());
});
测试1(600个请求22个字节,只有一个初始连接到页面)
总计600 KB请求
83 KB = 83,000字节/ 600请求=每请求138.33字节
数据发送= 22字节
138.33字节 - 22字节= 116.33字节开销消息发送
这是合理和相当不错的(尽管这似乎没有考虑firbase的定价页)。
我在等了一个半小时之后跑了第二个测试,所以实时数据库的使用情况可能会更新。 >测试2包含我认为可能是一个错误︰
测试2(20页重新发送一个请求)
共20页重新加载+ 20次请求总共96 KB
96 KB / 20 = 4.8 KB每次重新加载$ b $ b
我不认为这是正确的,这使我相信实时数据库的数据使用部分存在一个错误。我注意到,刷新时使用的数据将爬上大约2-4kb(我只有22个字节存储)。
我很确定这个用例很容易重现。我不打算把它看作是一个答案,它只是给出了更多的问题,但这正是我在运行这些测试用例时发现的。
谢谢
I am trying to compute the size of messages in firebase in order to accurately estimate the cost of my app.
I noticed when running that the realtime database calculator was showing larger than expected data sizes. To verify this, I started a toy application that has a single ref called "test" with the data:
{"foo": "bar"}
Going on other answers, my estimate is that this data is under 20 bytes.
Retrieving the data with this code:
firebase.database().ref("test").once("value", function(snapshot) {
console.log(snapshot.val());
});
Here is a jsfiddle showing this toy example.
I grab the ref and console.log the data. I have accessed this example under 10 times. When I look at the toy application's realtime database usage tab, it shows something like 30KB bandwidth used.
What other data is being sent to account for this large gap in expected data usage (10 * 20 bytes = 200 bytes) vs the actual 30KB sent?
Is there some initial overhead when initializing an app that adds to the data usage?
EDIT:
Following cartant's advice, I logged the frames being sent from the websocket. Here is what I found (Before this I see some initialization messages of about 200 bytes):
Data Length
{"t":"d","d":{"r":22,"a":"q","b":{"p":"/test","h":""}}} 55
{"t":"d","d":{"b":{"p":"test","d":{"foo":"bar"}},"a":"d"}} 58
{"t":"d","d":{"r":23,"a":"n","b":{"p":"/test"}}} 48
{"t":"d","d":{"r":22,"b":{"s":"ok","d":{}}}} 44
{"t":"d","d":{"r":23,"b":{"s":"ok","d":""}}} 44
So it seems like there is a ~200-250 byte overhead for any message. Can anyone confirm this? This still does not fully explain the gap I mentioned earlier (10 messages * 250 bytes = 2.5 KB vs the 30 KB recorded).
UPDATE:
The current bandwidth usage is up to 155 KB. I am not sure how this number is possible with 35 viewers on this post. In order to try to get a sense of this (I am still not sure how bandwidth is actually calculated), here are my thoughts:
200 bytes to initialize/connect
220 bytes per message (200 bytes of overhead + 20 bytes in message)
100 times sent (this is probably an overestimate, as there are 35 views on this post, but I have viewed it around 10 times myself)
(200 bytes + 220 bytes) * 100 views = 42000 bytes or 42 KB.
So to get to 155 KB either this was sent much more than 100 times, or there is some unexplained overhead. Also, I assume (which I do not know) that the overhead to initialize is 200 bytes and the overhead to send any message is 200 bytes.
I've run some more tests (reading 22 bytes) and think there is a possible bug in calculating bandwidth. If not, then the bandwidth rates on reload are very large. Here are my tests:
Test 1 (600 requests of 22 bytes with only one initial connect to the page)
83 KB total for 600 requests
83 KB = 83,000 bytes / 600 requests = 138.33 bytes per request
data sent = 22 bytes
138.33 bytes - 22 bytes = 116.33 bytes overhead per message sent
Which is reasonable and pretty good (although this does not seem to be factored in on firbase's pricing page).
I ran the second test after waiting for an hour and a half so the realtime database usage could update.
Test 2 contains what I think may be a bug:
Test 2 (20 page reloads sending one request)
96 KB total for 20 page reloads + 20 requests
96 KB / 20 = 4.8 KB per reload
I do not think this can be correct, which leads me to believe that there is a bug in the data usage portion of the realtime database. I noticed when refreshing that the data used would climb by around 2-4kb (I only have 22 bytes stored).
I am pretty sure that this use case is easily reproducible. I am not going to upvote this as its not really an answer, it just gives more questions, but it is what I found when running these test cases.
Thanks
这篇关于计算Firebase消息大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!