Score:1

What's the cheapest way to find the name of the last (sorted alphabetically) "directory" in a Google Cloud Storage bucket?

ml flag

At the moment I'm doing:

gsutil ls -l gs://myproject | sort | tail -n 1

It takes about 10-15 seconds, which is fine, but I worry what the cost of this operation is? If it affects the cost, there's 10million objects, in 1000 top-level "directories". And I'm on Archive storage class.

I've no idea if this is free/cheap/expensive, and if there's a better way?

https://cloud.google.com/storage/pricing

This link seems to suggest it's a Class A operation (ls is classed as storage.objects.list, presumably). But it's not clear to me if that cost is per object, or per list. Does a list with 10,000,000 files in it cost the same as a list of one file? Or does it cost 10,000,000 times more? I agree that the latter sounds ludicrous, but I felt I should check!

Thank you

Score:2
in flag

Pricing is per operation, and not per object. According to the pricing document you linked

(...) each request is considered one operation, regardless of the content sent or received as part of the request.

Considering this, from the viewpoint of money payed, there is no better solution, since you always have to make at least one request to list your files, which is where you stand now.

Codemonkey avatar
ml flag
Thank you, I managed to miss that line
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.