Bird
Raised Fist0
GCPcloud~5 mins

Request-based auto scaling in GCP - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes your app gets more visitors and needs more computers to handle the extra work. Request-based auto scaling automatically adds or removes computers based on how many requests your app gets. This helps keep your app fast and saves money by not using too many computers when they are not needed.
When your website traffic changes a lot during the day and you want to handle more visitors without slowing down.
When you run an online store that gets busy during sales and quiet at other times.
When you have a mobile app backend that needs to quickly respond to user requests without delay.
When you want to save money by only using the computers you need at the moment.
When you want your app to stay available even if many people use it at the same time.
Config File - app.yaml
app.yaml
runtime: python39
instance_class: F2
automatic_scaling:
  target_request_count_per_instance: 10
  min_instances: 1
  max_instances: 5

This file tells Google App Engine how to run your app.

runtime sets the programming language and version.

instance_class chooses the size of the computer running your app.

automatic_scaling controls how many instances run based on requests.

target_request_count_per_instance is the number of requests each instance should handle before adding more.

min_instances and max_instances set the limits for scaling.

Commands
This command uploads your app and the scaling settings to Google Cloud so it can start running with request-based auto scaling.
Terminal
gcloud app deploy app.yaml
Expected OutputExpected
Services to deploy: descriptor: [app.yaml] source: [/home/user/myapp] target project: [my-gcp-project] target service: [default] Do you want to continue (Y/n)? y Beginning deployment... Updating service [default]... ................................................................................................ Deployed service [default] to [https://my-gcp-project.uc.r.appspot.com] You can stream logs from the command line by running: gcloud app logs tail -s default To view your application in the web browser run: gcloud app browse
This command opens your deployed app in the web browser so you can see it working and test the scaling behavior.
Terminal
gcloud app browse
Expected OutputExpected
Launching default service in browser...
This command shows the current number of instances running your app, so you can check if auto scaling is working as expected.
Terminal
gcloud app instances list
Expected OutputExpected
SERVICE VERSION INSTANCE VM_ID VM_IP STATE default 20240601 instance-1 1234567890abcdef1234567890abcdef 35.233.123.45 RUNNING
Key Concept

If you remember nothing else from this pattern, remember: request-based auto scaling adjusts the number of app instances automatically based on how many requests each instance receives to keep your app fast and efficient.

Common Mistakes
Setting min_instances and max_instances to the same number.
This disables scaling because the number of instances cannot change, so your app cannot handle more or fewer requests dynamically.
Set min_instances to a low number like 1 and max_instances to a higher number like 5 to allow scaling up and down.
Setting target_request_count_per_second too high.
Each instance will get too many requests and become slow or unresponsive, causing poor user experience.
Choose a reasonable target like 10 requests per second per instance to balance load and performance.
Not deploying the app after changing the scaling settings.
Changes in the config file won't take effect until you deploy, so the app won't scale as expected.
Always run 'gcloud app deploy app.yaml' after editing the config file.
Summary
Create an app.yaml file with automatic_scaling settings to control request-based scaling.
Deploy the app using 'gcloud app deploy app.yaml' to apply the scaling configuration.
Use 'gcloud app instances list' to check how many instances are running and verify scaling behavior.

Practice

(1/5)
1. What does request-based auto scaling primarily adjust in a cloud service?
easy
A. The number of server instances based on incoming requests
B. The amount of storage space available
C. The network bandwidth allocation
D. The security settings of the service

Solution

  1. Step 1: Understand the purpose of request-based auto scaling

    Request-based auto scaling changes resources based on the number of incoming requests to handle load efficiently.
  2. Step 2: Identify what is adjusted

    The main resource adjusted is the number of server instances to match demand.
  3. Final Answer:

    The number of server instances based on incoming requests -> Option A
  4. Quick Check:

    Scaling adjusts instances = A [OK]
Hint: Auto scaling changes instance count, not storage or security [OK]
Common Mistakes:
  • Confusing scaling with storage or bandwidth changes
  • Thinking it adjusts security settings
  • Assuming it changes fixed resources regardless of requests
2. Which of the following is the correct way to set the minimum number of instances in a GCP service YAML configuration for request-based auto scaling?
easy
A. min-instances: 2
B. minInstances: 2
C. minimum_instances: 2
D. min_instances: 2

Solution

  1. Step 1: Recall GCP YAML syntax for scaling parameters

    GCP uses kebab-case for configuration keys like min-instances.
  2. Step 2: Identify the correct key format

    The correct key to set minimum instances is min-instances, not camelCase or underscored.
  3. Final Answer:

    min-instances: 2 -> Option A
  4. Quick Check:

    Use kebab-case keys like min-instances [OK]
Hint: Use kebab-case keys like min-instances in GCP YAML [OK]
Common Mistakes:
  • Using camelCase or underscores instead of kebab-case
  • Misspelling the key name
  • Confusing min-instances with max-instances
3. Given this snippet of a GCP service configuration for request-based auto scaling:
concurrency: 10
min-instances: 1
max-instances: 5

What happens when the service receives 50 simultaneous requests?
medium
A. The service scales down to 0 instances to save cost
B. The service stays at 1 instance because min-instances is set
C. The service scales up to 10 instances because concurrency is 10
D. The service scales up to 5 instances to handle the load

Solution

  1. Step 1: Understand concurrency and instance limits

    Concurrency 10 means each instance can handle 10 requests at once. Max-instances is 5, min-instances is 1.
  2. Step 2: Calculate needed instances for 50 requests

    50 requests / 10 concurrency = 5 instances needed, which matches max-instances.
  3. Final Answer:

    The service scales up to 5 instances to handle the load -> Option D
  4. Quick Check:

    Requests/concurrency = instances needed = 5 [OK]
Hint: Divide requests by concurrency, respect max-instances limit [OK]
Common Mistakes:
  • Ignoring max-instances limit
  • Confusing concurrency with max-instances
  • Assuming scaling down when load increases
4. You configured a GCP service with:
concurrency: 5
min-instances: 2
max-instances: 4

But the service never scales above 2 instances even under heavy load. What is the most likely cause?
medium
A. The concurrency value is too high, limiting scaling
B. The max-instances value is too low to allow scaling beyond 2
C. The min-instances value is preventing scaling down
D. The service needs a restart to apply scaling changes

Solution

  1. Step 1: Analyze max-instances and min-instances settings

    Max-instances is set to 4, min-instances is 2. Scaling cannot exceed max-instances.
  2. Step 2: Understand why scaling stops at 2

    If the service never goes above 2 instances, max-instances might be set too low or misinterpreted.
  3. Final Answer:

    The max-instances value is too low to allow scaling beyond 2 -> Option B
  4. Quick Check:

    Max-instances limits max scale = B [OK]
Hint: Check max-instances to allow scaling beyond min-instances [OK]
Common Mistakes:
  • Confusing min-instances with max-instances
  • Assuming concurrency limits scaling up
  • Forgetting to check applied config values
5. You want to optimize cost and performance for a GCP service that experiences unpredictable traffic spikes. Which configuration best balances fast scaling up and cost savings during idle times?
hard
A. Set concurrency to 1, min-instances to 0, max-instances to 10
B. Set concurrency to 50, min-instances to 5, max-instances to 5
C. Set concurrency to 10, min-instances to 1, max-instances to 10
D. Set concurrency to 100, min-instances to 10, max-instances to 20

Solution

  1. Step 1: Understand concurrency and instance settings impact

    Lower concurrency means more instances needed; min-instances controls baseline cost; max-instances limits scale.
  2. Step 2: Evaluate options for balancing cost and performance

    Set concurrency to 10, min-instances to 1, max-instances to 10 uses moderate concurrency (10), low min-instances (1) to save cost, and high max-instances (10) to handle spikes.
  3. Final Answer:

    Set concurrency to 10, min-instances to 1, max-instances to 10 -> Option C
  4. Quick Check:

    Moderate concurrency + low min + high max = balanced scaling [OK]
Hint: Moderate concurrency with low min and high max balances cost and spikes [OK]
Common Mistakes:
  • Setting concurrency too low causing many instances
  • Setting min-instances too high increasing cost
  • Setting max-instances too low limiting scaling
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