Why resource hierarchy matters in GCP - Performance Analysis
When working with cloud resources, the way they are organized affects how quickly we can manage them.
We want to know how the number of steps grows when we add more resources in a hierarchy.
Analyze the time complexity of listing all projects under multiple folders in a resource hierarchy.
// Pseudocode for listing projects
folders = listFolders(parentOrganization)
for folder in folders {
projects = listProjects(folder)
// process projects
}
This sequence lists folders under an organization, then lists projects inside each folder.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Listing projects inside each folder.
- How many times: Once per folder found under the organization.
As the number of folders grows, the number of project listing calls grows too.
| Input Size (n folders) | Approx. API Calls/Operations |
|---|---|
| 10 | 1 (listFolders) + 10 (listProjects) = 11 |
| 100 | 1 + 100 = 101 |
| 1000 | 1 + 1000 = 1001 |
Pattern observation: The total calls grow roughly in direct proportion to the number of folders.
Time Complexity: O(n)
This means the time to list all projects grows linearly with the number of folders.
[X] Wrong: "Listing projects under all folders takes the same time no matter how many folders there are."
[OK] Correct: Each folder requires a separate call to list its projects, so more folders mean more calls and more time.
Understanding how resource hierarchy affects operation counts shows you can think about cloud resource management efficiently.
"What if we changed the hierarchy to have projects directly under the organization instead of folders? How would the time complexity change?"