Database Reference.listen() is very slow for large responses
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với triển khai sseclient của Firebase Admin SDK được Reference.listen() sử dụng, sau đó so sánh hành vi đọc response của nó với btubbs/sseclient.py được liên kết. Tái hiện vấn đề bằng bài kiểm tra Raspberry Pi được cung cấp và xác nhận rằng các response lớn của listen() không còn mất khoảng 10 giây hoặc sử dụng gần 100% CPU, trong khi callback vẫn nhận được event hoàn chỉnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- Python
- Star
- 1.2k
- Fork
- 359
- Merge trung bình
- 3 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của firebase/firebase-admin-python
-
api: remoteconfig
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
firebase/firebase-admin-python#957 · 1 bình luận ·
-
api: database type: feature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
firebase/firebase-admin-python#978 · 1 bình luận ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) Đang mởapi: auth
firebase/firebase-admin-python#949 · 2 bình luận · 1 reaction · 1 người được giao ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
firebase/firebase-admin-python#945 · 1 bình luận · 1 reaction ·
Tất cả issue của firebase/firebase-admin-python
Issue tương tự
-
essnmx good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
[Feature] 奇物选择添加优先级 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
syfoud/Simulated_Scepter#174 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Giskard-AI/giskard-oss#2840 · 1 bình luận ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Đang mởarea: repo bug perceived difficulty: 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
yeti-platform/yeti#1380 ·