【发布时间】:2020-04-27 15:48:47
【问题描述】:
操作系统:Mac OS Catalina v 10.15.1
Python 版本:Python 3.7.1
Firestore pip 包版本:google-cloud-firestore 1.6.1
我正在一个非常简单的 Firestore 数据库上测试简单的数据库读取和写入。我正在查看包含 1 个数据项(字符串)的单个文档的单个集合;但是,当我尝试写入时(如下所示),我拥有的计时器(也在下面的代码中)显示第一次写入需要 超过 30 秒。读取也存在相同的行为。
但是,这仅在此 python 脚本中的第一次写入/读取时出现。所有后续写入/读取的时间大约为 100 毫秒(对于这么小的数据库来说仍然很慢)。我无法在 Internet 上找到此问题的副本,并且 Firestore Python SDK 文档中也没有提及此类行为。我在我的机器上本地运行以下代码。
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import datetime
cred = credentials.Certificate("./path/to/adminsdk.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
start = datetime.datetime.now()
#the below write takes >30 seconds to execute
doc_ref = db.collection(u'test_collection').document(u'test_document')
doc_ref.set({u'test_field':'data'})
time_after_first = datetime.datetime.now()
print(time_after_first - start)
#The below read takes 80 ms to execute
doc_data = doc_ref.get()
print(doc_data.get('test_field'))
print(datetime.datetime.now()-time_after_first)
print("done")
我在另一个 StackOverflow 帖子上发现了一个建议,建议使用 on_snapshot 而不是 get;但是,问题仍然存在(仅在大约 30 秒后才收到 DocumentSnapshot)。另外,这个问题不是get独有的,set、update等也是如此。
任何提示将不胜感激!
【问题讨论】:
-
如果您对将单个文档写入云托管数据库的性能不满意,我认为 Stack Overflow 不适合发帖。我建议改为发布到 Firestore 讨论组。 groups.google.com/forum/#!forum/google-cloud-firestore-discuss
标签: python firebase google-cloud-platform google-cloud-firestore