Database Reference.listen() is very slow for large responses
还没有人认领这个 Issue。
评估
调研方向
从 Firebase Admin SDK 中 Reference.listen() 使用的 sseclient 实现开始,然后将其读取响应的行为与链接的 btubbs/sseclient.py 进行比较。使用提供的 Raspberry Pi 测试重现该问题,并确认大型 listen() 响应不再耗时约 10 秒或占用近 100% 的 CPU,同时 callback 仍能接收到完整事件。
由索引模型根据 Issue 内容生成。
描述
Describe your environment
- Operating System version: Linux raspberrypi 4.19.97+ (On a Raspberry Pi Zero W)
- Firebase SDK version: 5.2.0
- Firebase Product: database
- Python version: 3.7.3
- Pip version: 18.1
Describe the problem
Reading a large event in response to calling Reference.listen() is extremely slow on a Raspberry Pi Zero. This looks very similar to https://github.com/nhorvath/Pyrebase4/issues/45 and I noticed that the sseclient here is based on that from Pyrebase.
From reading the sseclient code, the Firebase Admin SDK seems to have solved the quadratic regex scanning issue that the sseclient in Pyrebase4 has, but it still reads the response one character at a time, which I suspect is the root issue. It looks like this is solved in https://github.com/btubbs/sseclient/blob/master/sseclient.py by reading in chunks when short reads are supported.
Steps to reproduce:
Modify the test code below to add a working databaseURL and run it. On my Raspberry Pi Zero W, it outputs:
0 ms: Initializing app...
1 ms: Getting DB reference...
17 ms: Putting 20000 bytes...
1122 ms: Getting data...
1347 ms: Got 20000 bytes with get().
1349 ms: Listening for data...
11686 ms: Got 20000 bytes with listen().
That is, listen() takes about 10 000 ms (with close to 100% CPU usage) to get and read the response, while get() takes 200 ms.
Relevant Code:
import firebase_admin
import firebase_admin.db
import sys
import time
count = 2000
nonsense = "abcedefghi"
start_time = time.time()
def log(msg):
t = int(1000 * (time.time() - start_time))
print(str(t) + " ms: " + msg)
log("Initializing app...")
firebase_admin.initialize_app(options={'databaseURL': 'https://XXXXXXXXXX.firebaseio.com/'})
log("Getting DB reference...")
ref = firebase_admin.db.reference("bringert_test_streaming_speed")
data = nonsense * count
log("Putting " + str(len(data)) + " bytes...")
new_data=ref.push(data)
log("Getting data...")
log("Got " + str(len(new_data.get())) + " bytes with get().")
def callback(event):
if event.event_type == "put":
log("Got " + str(len(event.data)) + " bytes with listen().")
sys.exit(0)
log("Listening for data...")
new_data.listen(callback)
- 主要语言
- Python
- 星标
- 1.2k
- 派生
- 359
- 平均合并
- 3 天 9 小时
- 30 天内合并 PR
- 3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-admin-python 的其他 Issue
-
api: remoteconfig
难度 2/5 1-3 小时 新手友好度 75/100
firebase/firebase-admin-python#957 · 1 条评论 ·
-
api: database type: feature request
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 45/100
firebase/firebase-admin-python#978 · 1 条评论 ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) 未关闭api: auth
firebase/firebase-admin-python#949 · 2 条评论 · 1 个 reaction · 已指派 1 人 ·
-
难度 4/5 3-5 天 新手友好度 43/100
firebase/firebase-admin-python#945 · 1 条评论 · 1 个 reaction ·
查看 firebase/firebase-admin-python 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·