How list object in Google Cloud Storage is calculated? - google-cloud-storage

Just a clarification, I know List objet to see all files in a bucket is a class A Operation in Google Cloud Storage, My question does it cost the same to list 10 files in a bucket or 1 Millions, how the cost is calculated exactly.

Each Object: list call returns at most 1,000 objects. See the description of maxResults here:
https://cloud.google.com/storage/docs/json_api/v1/objects/list
You can request fewer, but you cannot request more than 1,000 in each RPC. To get 1 million objects you need to make 1,000 calls, so it is about 1,000 times more expensive to get 1 million objects vs. getting 10 objects.

Related

Firestore reading quota

I have 1 collection on Firestore database and there are 2000 test documents (records) in this collection. Firestore gives free 50.000 daily reading quota. When I run my Javascript code to query documents, my reading quota decreases more than I expected. If I count all documents by using one query, is that mean "2000 reading" operation or only "1 reading" operation?
Currently firestore doesn't have any native support for aggregate queries over documents like sum of some fields or even count of documents.
So yes, when you count total number of documents in the collection then you are actually first fetching atleast the references for those docs.
So, having 2000 documents in a collections and using a query to count number of docs in that collection you are actually doing 2000 reads.
You accomplish what you want, you can take a look at the following also https://stackoverflow.com/a/49407570
Firebase Spark free give you
1 GiB total - size of data you can store
10GiB/month - Network egress Egress in the world of
networking implies traffic that exits an entity or a network
boundary, while Ingress is traffic that enters the boundary of a
network In short network bandwidth on database
20K/day Writes
50K/day Reads
20K/day Del
If You reading 2000 documents depends on calling a single call read cause one read if you reading multipal at one consider 1 reads the answer is depends how you reads you calling
Firebase Console also consume some reads writes thats why quota decreases more than you expected

Do Documents reads count sub-collections in Firestore?

my daily quotas has just been resetted so I figured out it was the moment to go on my Firestore user interface to know how much reads where counted simply by retrieving documents.
I have 11 documents each of them have 3 sub-collections (inside of them a certain number of documents) plus 1 dummy document with no sub collection and connecting to the firestore UI counts me 36 reads (1 document is opened - its sub collection are closed);
I though it was 1 read/document retrieved without taking in account sub collections?
36 reads how is this even possible? Would this mean my 12 documents are read 3 times each?
here is my data structure:
myCollection: {
$docId: {
data:myDate
subCollection1:{
$subDocId
}
subCollection2:{
$subDocId
}
subCollection3:{
$subDocId
}
}
}
I have tested it on a completely fresh project. Indeed using the front end UI in the console it used around 2 times more than the number of documents. I created 6 documents with one field in one collection and every listing gave me usage of 12 reads. If you add some sub-collection it might be more.
But first of all I think that console UI is not meant to be used as a working interface, but rather for support/design purposes which means entered occasionally. With this assumption matter of cost effectiveness is less important. If you have 50 000 reads free each day and 0.036$ per 100 000 reads, a few hundred reads more when using the UI just not make any difference in costs.
The larger number of reads might be the result of implementation. Firestore is billed based on API calls, probably some items are queried even if they are not seen at the beginning to improve user experience or due to some other feature of the UI.
Firestore cost documentation here.

Firebase Realtime Database Pricing with Query

I have a question about the firebase database pricing. I have about 400,000 rows in the leaderboard of my database, but in my app I just want to load the last 500 rows, so my question will I get charged for the 500 rows loaded when I run the query or will I get charged for all 400,000 rows.
Realtime database charges 5$ per gb stored and 1$ per gb downloaded. I did the calculation with Firestore and found that Realtime Database would be way cheaper if i get charged for the 500 rows and not the 400,000 rows.
I searched all documentation and have not found anything about queries: https://firebase.google.com/pricing
https://firebase.google.com/docs/database/usage/billing
Can someone tell me if I get charged for just the 500 rows in my collection or for all the data in the collection and if there is a way to only get charged for the 500 rows maybe with security rules?
Here is my query code:
let queryRef = ref.child("Leaderboard").queryOrdered(byChild: "totalStars").queryLimited(toLast: 500)
How the database looks like. (It will have about 500,000 childs same as these and be loaded 200,000 per day, But I just want to be priced on the top 500 that I load and not the whole 500,000 each time a user loads the leaderboard is it possible?)
You will only be charged for the number of Firestore Documents corresponding to the result of your query (not to the number of docs in the collection).
So in your case a maximum of 500 reads, since you would limit the Query to 500 documents.
On the other hand, note that the Realtime Database queries are not shallow (while the Firestore ones are) and therefore if you query for a JSON node you'll get the entire tree under this node.
Renaud's answer is the correct one but let me add some additional information and restate that:
With the Firebase Real Time Database for downloads you are charged for
what is downloaded and not how many nodes you are querying.
So the key is to reduce the amount of data you're downloading. Your nodes are already pretty shallow however, there's a huge savings to be made because in your current structure, the node key (the users uid) is duplicated within the node as a child node, and that's not needed.
You can always get the node key with snapshot.key and remove that child node. So it would look like
uid
fullName: "Logan Paul"
stars: 40
Also, I think your calculations are off a bit. It looks like each node would be about 100 bytes of data, and Firebase strings are UTF-8 Encoded so if you download 500 nodes per user per day and you have 200,000 users, that about 38Gb per day (as binary).
Roughly 400 bytes * 500 nodes * 200,000 users * 0.000000000931322574615479 bytes per Gb = 38Gb
so about $38 a day if I did my math correctly.

Understanding Firebase Cloud Firestore Billing

I'm trying to understand Firestore's billing but don't understand exactly what a read/write/delete request is.
If I delete 100,000 items in a single request does that count as 1 delete request or 100,000 delete request?
Also, if a single query returns 250 rows (documents?) does that count as a single read or 250 read requests?
Read and write operations are billed per document affected. So, your examples would incur the cost of 100,000 deletes and 250 reads.

Maximum size of a document in firestore?

I want create a document that containing about 20 million objects.
The structure like that:
documentID
---- key1
-------- object1
-------------name: "test1"
-------------score: 123
I don't know the limitation of a document size in firestore, so can you help me any reference or information about that?
Thanks!
The maximum size is roughly 1 Megabyte, storing such a large number of objects (maps) inside of a single document is generally a bad design (and 20 million is beyond the size limit anyway).
You should reconsider why they need to be in a document, rather than each object being their own document.
Cloud Firestore's limits are listed in the documentation.
Have you looked at Firestore sub-collections?
You can store the main item as a document in one top-level collection, and all of its underlying data could be in a sub-collection of that document.
There is no limit to how many object records a sub-collection can contain when those objects are stored as child documents of that sub-collection.
So 20M records should not be an issue.
If you want to save objects bigger than 1mb you should use cloud storage, the limit is 5tb per object:
There is a maximum size limit of 5 TB for individual objects stored in Cloud Storage. There is an update limit on each object of once per second, so rapid writes to a single object won't scale.
Google cloud storage
If you want to check the size of a document against the maximum of 1 MiB (1,048,576 bytes), there is a library that can help you with that:
https://github.com/alexmamo/FirestoreDocument-Android/tree/master/firestore-document
In this way, you'll be able to always stay below the limit.