Azure vs GCP part 4: Web Apps and App Engine Scaling features
Tags: azure, gcp, cloud
Published: 2018-03-03 10:54:13

---
title: "Azure vs GCP part 4: Web Apps and App Engine Scaling features"
published: true
description: In this series, I compare Azure and GCP as C# developer
tags: azure,gcp,cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/m57mmv4hgz9xrskaital.PNG
---

I understand how I can deploy my dotnet core application to Azure Web Apps and GCP App Engine. How about scaling? Why do I care such thing as a developer? Because one of the reasons why I want to use cloud platform is to utilize its features :)

# Why Scaling matters
Deploy an application to single instance is easy, but scaling-out is difficult if you manage infrastructure by yourself.

- Add servers
- Manage IP addresses
- Add load balancing
- Manage name resolution
- Deploy application to multiple servers by having perfect control of versions
- And more.

But we need to scale up and down depending on requests to optimize the resource usages!

While both platform support auto/manual scaling, how to set them seems to be quite different.

# Azure Web Apps
Azure provides performance related settings as "plan".

1\. First of all, select appropriate plan. Go to App Service plan you created and select "Scale up", then it gives you available plans. 

In this case, I selected "S1" which gives me up to 10 instances for auto scale, with 1 Core CPU and 1.75 GB RAM.
![plan](https://thepracticaldev.s3.amazonaws.com/i/3dt8orys4qeovqpp68uy.PNG)

2\. Then go to "Scale out" menu. If you select instance count by using slide bar, it is manual scale settings. I set 6 instances manually.
![scale](https://thepracticaldev.s3.amazonaws.com/i/syghxuaxq95nvk5uz1nx.PNG)

3\. To enable auto-scale, click "Enable autoscale" and set the settings. Here again, if you specify "Scale to a specific instance count", it becomes manual scaling. Thus I select "Scale based on a metric". Click "Add a rule".
![scale](https://thepracticaldev.s3.amazonaws.com/i/7qsvv1dc5w8q0mygqa70.PNG)

4\. Then I specify CPU threshold rule and add. You can add multiple rules if you need. I also set max instance count to 10.
![scale](https://thepracticaldev.s3.amazonaws.com/i/wp081epctz9ulb96273w.PNG)

5\. Finally, name the rule and save it.

## Test it!
To test the auto-scaling, the easiest way is to use performance test.

1\. Go to Web Apps you want to test, and click "Performance test".
![test](https://thepracticaldev.s3.amazonaws.com/i/1zdunw5gd05f974f66zj.PNG)

2\. Click add to add test. It's straight forward so I won't explain detail here, but run the test long enough to exceed the threshold. *This creates VSTS account background.
![test](https://thepracticaldev.s3.amazonaws.com/i/yltwltevfzlaw36adwpt.PNG)

3\. Once test created, select the created test, which navigates you to test page. It takes several minutes before the test actually starts. Once test start, check how many instances actually allocated.

However, the default template app didn't work very well as I expected to. So many failed access, yet no auto-scale actually happen as CPU usage didn't exceed the threshold. In this case, manual scale may make sense.

# GCP App Engine
As far as I research, the only way to change it is via app.yaml. If someone knows how to do this via UI, let me know please.

1\. In your dotnet core project, right click solution and click "Generate app.yaml and Dockerfile".
![publish](https://thepracticaldev.s3.amazonaws.com/i/g1r047pv1612e79vyitk.PNG)

2\. For auto scaling, add auto scaling section. See [here](https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml#services) for more detail. BTW, there are default value for each, so you don't have to set it to enable auto-scaling if default value works.

```yaml
automatic_scaling:
  min_num_instances: 1
  max_num_instances: 15
  cool_down_period_sec: 180
  cpu_utilization:
    target_utilization: 0.6
```
- min_num_instances: Must be 1 or greater, default is 2
- max_num_instances: Default is 20
- cool_down_period_sec: Must be greater than or equal to 60 seconds. Default is 120.
- target_utilization: Target CPU utilization. Default is 0.5.

If you do manual scaling, use manual_scaling section.

```yaml
manual_scaling:
  instances: 5
```

3\. For instance resource settings, specify in resources section. See [here](https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml#resource-settings) for more detail.

```yaml
resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
  volumes:
  - name: ramdisk1
    volume_type: tmpfs
    size_gb: 0.5
```

4\. Once everything set, publish to Google Cloud. In this case, to illustrate this, I set manual scaling to 5 instances with resource specified above. Once deploy completed, go to App Engine | Versions. Click "View" for config.

![publish](https://thepracticaldev.s3.amazonaws.com/i/nwigtdm9u1mxu66hrpda.PNG)

5\. You can see the configuration information.
![publish](https://thepracticaldev.s3.amazonaws.com/i/dehez4suozcswhzldf26.PNG)

6\. Go to instances to see each instance information. I don't know the reason but there are only four instances, not five though. Maybe it comes up later?
![publish](https://thepracticaldev.s3.amazonaws.com/i/o1g3q9xljvv99qll3vlh.PNG)

# Summary
Both platform offers both manual and auto scaling features, with various resources. This is what I found.

- Azure offers excellent UI experience with easy to understand plans.
- GCP offers version embed configuration with more granular controls.


# References

[Developing apps that scale automatically with Google App Engine](https://www.youtube.com/watch?v=HN5JKvvKUgQ)
[Cloud Loading Testing in Visual Studio Team Services](https://www.youtube.com/watch?v=tX-QvDWEl74)

Ken