[英]Firebase Storage very slow compared to Firebase Hosting
任何人都知道為什么與 firebase 托管相比,firebase 存儲會如此緩慢?
結果
16ms
2.23s (2.22s is TTFB)
存儲下載相同圖像的時間: 2.23s (2.22s is TTFB)
1.72s (1.70s is TTFB)
這在測試中一遍又一遍地重復。 有什么方法可以將其加速到合適的時間,還是 Firebase 存儲無法用於小文件(圖像/拇指)?
比較
500ms
30ms
20ms
額外信息:
我找到了解決方案。
如果您已將文件上傳到存儲,請訪問: https : //console.cloud.google.com/storage/browser?project=your_project > 選擇您的存儲桶 > 選擇所有感興趣的文件並單擊公開(或類似的 - 我'不是英語母語)。
要默認公開所有新上傳的文件,您需要安裝 Google Cloud SDK ( https://cloud.google.com/sdk/docs/ ) 並從您的命令行對您的存儲桶使用以下命令:
gsutil defacl set public-read gs://your_bucket
之后,我所有當前和新的圖像都可以在這里找到 storage.googleapis.com/my_project.appspot.com/img/image_name.jpg 並且下載時間肯定更短。
托管 = 存儲 + CDN,因此您真正看到的是您點擊了附近的 CDN,而不是直接進入 GCS 或 S3 存儲桶。 Cloudinary/Imgix 也是如此。 這就是托管的性能比存儲好得多的原因。
解決 AWS 和 GCP 之間 TTFB 如此不同的問題:不幸的是,這是 GCS 與 S3 的一個已知問題(請參閱這篇很棒的博客文章,並進行深入的性能分析)。 我知道這個團隊正在努力解決這個問題,但是“在它前面添加一個 CDN”路線將提供一個更快的解決方案(前提是您不需要限制訪問,或者您的 CDN 可以授權請求)。
除了@Ziwi 的回答。 我認為直接在 Firebase 中更改規則也可以
// Only a user can upload their profile picture, but anyone can view it
service firebase.storage {
match /b/<bucket>/o {
match /users/{userId}/profilePicture.png {
allow read;
allow write: if request.auth.uid == userId;
}
}
}
來源是https://firebase.googleblog.com/2016/07/5-tips-for-firebase-storage.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.