22
votes

Anyone know why firebase storage would be so ridiculously slow compared to firebase hosting?

Results

  • Time to download image of firebase hosting: 16ms
  • Time to download same image from firebase storage: 2.23s (2.22s is TTFB)
  • Time to download same image from firebase storage (Asia Pacific Region): 1.72s (1.70s is TTFB)
  • (File size: 22.7kb / jpeg / firebase storage has read open to everyone)

This is repeated over and over in tests. Is there any way to speed this up to a decent time, or is firebase storage unusable for small files (images/thumbs)?

For Comparison

  • S3 North Cal - approximately 500ms
  • S3 Asia Pacific - Approximately 30ms
  • Cloudinary - Approximately 20ms

Extra info:

  • I am based in Australia.
  • Exact same files. Always images under 100kb.
  • The slow down is always in the TTFB according to dev tools.
  • Hosting URL: https://.firebaseapp.com/images/thumb.jpg
  • Storage URL: https://firebasestorage.googleapis.com/v0/b/.appspot.com/o/thumb.jpg?alt=media&token=
3
So currently there are really no option to use firebase storage for photos with reasonable downloading time? It's about 10 times slower than getting photo from my ftp server (10$ per year). It's difficult to believe that such a big service like firebase has that kind of problem. I found that here console.cloud.google.com/storage/browser I can set every photo to have a public link and then getting photo from that public link is blazing fast (about 50ms). So now the question is: is there any way to make every uploaded photo public?Żywy
Makin every photo public is now available, using the GUI in cloud console.DauleDK

3 Answers

18
votes

I found the solution.

If you have your files already uploaded to storage go to: https://console.cloud.google.com/storage/browser?project=your_project > pick your bucket > select all interesting files and click Make public (or something similar - I'm not english native).

To have all new uploaded files public by default you need to install Google cloud SDK (https://cloud.google.com/sdk/docs/) and from your command line use the following command for your bucket:

gsutil defacl set public-read gs://your_bucket

After that all my current and new images are available here storage.googleapis.com/my_project.appspot.com/img/image_name.jpg and downloading time is definitely shorter.

2
votes

Hosting = Storage + CDN, so really what you're seeing is you hitting a CDN near you, rather than going directly to the GCS or S3 bucket. Same is true with Cloudinary/Imgix. This is why performance is so much better for Hosting than Storage.

Addressing the issue of TTFB being so different between AWS and GCP: unfortunately this is a known issue of GCS vs S3 (see this great blog post w/ in depth perf analysis). I know this team is working to address this problem, but going the "stick a CDN in front of it" route will provide a faster solution (provided you don't need to restrict access, or your CDN can authorize requests).

Note: GCP has announced a Sydney region (announcement blog post) to be launched in 2017, which might help you.

0
votes

In addition to @Ziwi answer. I think it is also ok to change rules directly in 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;
    }
  }
}

The source is https://firebase.googleblog.com/2016/07/5-tips-for-firebase-storage.html

enter image description here