Database Reference.listen() is very slow for large responses
まだ誰も着手していません。
評価
調査の方向性
Reference.listen() で使用される Firebase Admin SDK の sseclient 実装から始め、レスポンスの読み取り動作を、リンク先の btubbs/sseclient.py と比較します。提供されている Raspberry Pi のテストを使って問題を再現し、大きな listen() レスポンスで約 10 秒かかったり CPU をほぼ 100% 使用したりすることがなくなり、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時間
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 · 担当者 1 名 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 43/100
firebase/firebase-admin-python#945 · コメント 1 件 · リアクション 1 件 ·
firebase/firebase-admin-python の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 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 ·