Bird
Raised Fist0
GCPcloud~10 mins

Performance optimization in GCP - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable autoscaling for a Google Cloud Compute Engine instance group.

GCP
gcloud compute instance-groups managed set-autoscaling [1] --max-num-replicas=10 --min-num-replicas=1 --target-cpu-utilization=0.6 --zone=my-zone
Drag options to blanks, or click blank then click option'
Amy-instance-group
Bmy-instance-template
Cmy-zone
Dmy-project
Attempts:
3 left
💡 Hint
Common Mistakes
Using the instance template name instead of the instance group name.
Confusing zone or project with the instance group.
2fill in blank
medium

Complete the code to create a Cloud CDN-enabled backend service.

GCP
gcloud compute backend-services create [1] --enable-cdn --protocol=HTTP --port-name=http --global
Drag options to blanks, or click blank then click option'
Amy-instance-group
Bmy-load-balancer
Cmy-backend-service
Dmy-cdn-config
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance group or load balancer names instead of backend service name.
Trying to use a CDN config name which is not a resource.
3fill in blank
hard

Fix the error in the Terraform snippet to enable autoscaling on a GCP instance group.

GCP
resource "google_compute_autoscaler" "autoscaler" {
  name   = "autoscaler-example"
  target = google_compute_instance_group_manager.example.[1]

  autoscaling_policy {
    max_replicas    = 5
    min_replicas    = 1
    cpu_utilization {
      target = 0.6
    }
  }
}
Drag options to blanks, or click blank then click option'
Aself_link
Binstance_template
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance_template or name instead of self_link.
Using id which is not the correct reference.
4fill in blank
hard

Fill both blanks to configure a Cloud Storage bucket for website hosting with caching.

GCP
resource "google_storage_bucket" "website_bucket" {
  name          = "my-website-bucket"
  location      = "US"
  website {
    main_page_suffix = [1]
    not_found_page   = [2]
  }
  uniform_bucket_level_access = true
}
Drag options to blanks, or click blank then click option'
A"index.html"
B"404.html"
C"default.html"
D"error.html"
Attempts:
3 left
💡 Hint
Common Mistakes
Using error.html instead of 404.html for not found page.
Using default.html which is not standard.
5fill in blank
hard

Fill all three blanks to create a Cloud Run service with autoscaling based on concurrency and CPU utilization.

GCP
resource "google_cloud_run_service" "service" {
  name     = "my-service"
  location = "us-central1"

  template {
    spec {
      containers {
        image = "gcr.io/my-project/my-image"
        resources {
          limits = {
            cpu = [1]
          }
        }
      }
      container_concurrency = [2]
    }
  }

  traffic {
    percent         = 100
    latest_revision = true
  }

  autogenerate_revision_name = true

  metadata {
    annotations = {
      "autoscaling.knative.dev/target" = "[3]"
    }
  }
}
Drag options to blanks, or click blank then click option'
A"1"
B80
C"80"
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for CPU limits or annotations.
Confusing concurrency with autoscaling target values.

Practice

(1/5)
1. Which of the following is the best way to improve the performance of a Google Cloud Compute Engine instance?
easy
A. Choose a machine type with more CPUs and memory
B. Use a smaller disk size to reduce cost
C. Disable autoscaling to keep resources fixed
D. Use only standard persistent disks for all workloads

Solution

  1. Step 1: Understand machine types impact

    More CPUs and memory allow the instance to handle more work faster.
  2. Step 2: Evaluate other options

    Smaller disks reduce storage but do not improve performance; disabling autoscaling limits flexibility; standard disks are slower than SSDs.
  3. Final Answer:

    Choose a machine type with more CPUs and memory -> Option A
  4. Quick Check:

    More CPU and memory = better performance [OK]
Hint: More CPUs and memory usually mean better performance [OK]
Common Mistakes:
  • Thinking smaller disks improve speed
  • Disabling autoscaling helps performance
  • Ignoring disk type impact
2. Which of the following is the correct way to enable autoscaling on a Google Kubernetes Engine (GKE) cluster?
easy
A. Use the kubectl autoscale command with CPU utilization target
B. Disable autoscaling to save costs
C. Set the number of nodes manually and never change it
D. Use only preemptible VMs without autoscaling

Solution

  1. Step 1: Understand autoscaling in GKE

    Autoscaling adjusts the number of pods based on CPU or other metrics automatically.
  2. Step 2: Identify correct command

    The kubectl autoscale command sets autoscaling with CPU target, enabling dynamic scaling.
  3. Final Answer:

    Use the kubectl autoscale command with CPU utilization target -> Option A
  4. Quick Check:

    Autoscale command enables dynamic scaling [OK]
Hint: Use kubectl autoscale with CPU target to enable autoscaling [OK]
Common Mistakes:
  • Manually setting fixed node counts
  • Disabling autoscaling to save costs
  • Using preemptible VMs without autoscaling
3. You have a Compute Engine instance with an attached standard persistent disk. You want to improve disk performance. Which change will have the most impact?
medium
A. Switch to a larger standard persistent disk
B. Switch to a balanced persistent disk
C. Switch to an SSD persistent disk
D. Add more CPUs to the instance

Solution

  1. Step 1: Understand disk types and performance

    Standard persistent disks are slower; SSD persistent disks offer much better IOPS and throughput.
  2. Step 2: Evaluate options

    Larger standard disks increase capacity but not speed; balanced disks are better than standard but slower than SSD; adding CPUs does not improve disk speed.
  3. Final Answer:

    Switch to an SSD persistent disk -> Option C
  4. Quick Check:

    SSD disks improve disk performance most [OK]
Hint: SSD disks give best disk speed improvement [OK]
Common Mistakes:
  • Confusing disk size with speed
  • Thinking more CPUs improve disk speed
  • Choosing balanced disks over SSD for max speed
4. A Cloud Function is running slower than expected. You find the function has a memory limit of 256 MB. What is the best way to improve its performance?
medium
A. Reduce the memory allocation to 128 MB
B. Increase the memory allocation to 1 GB
C. Disable logging to speed up execution
D. Change the runtime to an older version

Solution

  1. Step 1: Understand memory impact on Cloud Functions

    More memory increases CPU allocation, improving performance.
  2. Step 2: Evaluate other options

    Reducing memory slows function; disabling logging has minimal effect; older runtimes may be slower or unsupported.
  3. Final Answer:

    Increase the memory allocation to 1 GB -> Option B
  4. Quick Check:

    More memory means more CPU and faster execution [OK]
Hint: More memory means more CPU for Cloud Functions [OK]
Common Mistakes:
  • Reducing memory to save cost
  • Disabling logging expecting big speedup
  • Using older runtimes for speed
5. You manage a web app on Google App Engine Standard environment. The app experiences high traffic spikes causing slow responses. Which combination of actions will best optimize performance and cost?
hard
A. Disable Cloud CDN and increase instance memory
B. Set a fixed number of instances and disable autoscaling
C. Use only manual scaling with large instance types
D. Enable autoscaling with a minimum number of instances and use Cloud CDN

Solution

  1. Step 1: Understand autoscaling benefits

    Autoscaling adjusts instances to traffic, handling spikes efficiently and saving cost during low traffic.
  2. Step 2: Use Cloud CDN to reduce backend load

    Cloud CDN caches content closer to users, reducing latency and backend requests.
  3. Final Answer:

    Enable autoscaling with a minimum number of instances and use Cloud CDN -> Option D
  4. Quick Check:

    Autoscaling + CDN = best performance and cost [OK]
Hint: Combine autoscaling and CDN for best speed and cost [OK]
Common Mistakes:
  • Fixing instance count causes wasted resources
  • Manual scaling ignores traffic spikes
  • Disabling CDN increases backend load
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard