UCONN

UCONN
UCONN

Chapter 11: App Engine

Chapter 11. App Engine:

Fully managed applications

  • What is App Engine, and when is it a good fit?

  • Building an application using the Standard and Flex versions

  • Managing how your applications scale up and down

  • Using App Engine Standard’s managed services


Computing platforms, representing a large variety in terms of complexity,

flexibility, and performance.


Compute Engine is an example of low-level infrastructure.

App Engine is a fully managed cloud computing environment.

Consolidate all of the work needed when deploying and running your applications.

Two separate environments that have some important differences.

One environment is built using open source tools like Docker containers


Containers are packages of software that contain all of the necessary

elements to run in any environment. In this way, containers virtualize

the operating system and run anywhere, from a private data center to

the public cloud or even on a developer’s personal laptop.


Proprietary technology that allows Google to do interesting things when

automatically scaling your app.

Fully managed computing environment complete with storage, caching,

computing, scheduling.

App Engine handles sudden spikes of traffic sent to your application.

Periods when your application is inactive don’t cost you any money.

App Engine Flexible Environment provides a fully managed

environment with fewer restrictions.

11.1. Concepts

The API layer has a few more organizational concepts that you’ll need to

understand to use App Engine.

App Engine keeps track of the versions of those components. 


11.1.1. Applications

Host your work is the top-level application.

Each of your projects is limited to one application, with the idea that each project should have one purpose.

The application acts as a container for your code.

App Engine section in the left-side navigation of the Cloud Console.

Choose a language (for example, Python);

Choose the location of your application


11.1.2. Services

Services on App Engine provide a way to split your application into smaller, more

manageable pieces.

Similar to microservices, App Engine services act as independent components of

computing.

Can access the same shared cron.


The cron command-line utility is a job scheduler on Unix-like operating systems.

Users who set up and maintain software environments use cron to schedule jobs,

also known as cron jobs, to run periodically at fixed times, dates, or intervals.


https://crontab.guru/


CronJob is meant for performing regular scheduled actions such as backups, report

generation, and so on. One CronJob object is like one line of a crontab (cron table) file

on a Unix system. It runs a Job periodically on a given schedule, written in Cron format.


API from any of the various services you might have as part of your application.

The service itself consists of your source code files and extra configuration, such as

which runtime to use (for App Engine Standard).

Deploy new versions of your reminder service to your application without having to

touch the web application service.

Isolate changes between related systems can be useful, particularly with large

applications built by large teams.

11.1.3. Versions

Point-in-time snapshots of a service.

Version of your service corresponds to the code in that directory at the exact time

that you decided to deploy it to App Engine.

Code that you deploy in that first service becomes the default version of that service. 


11.1.4. Instances

App Engine uses the concept of an instance to mean a chunk of computing capacity

for your application.

Instances are the computing units that App Engine uses to automatically scale your

application.



Instances represent an abstract chunk of CPU and memory available to run your application inside a special sandbox. 

Scale up and down automatically based on how many requests are being sent to your

application.

App Engine Flex is built on top of Compute Engine and Docker containers, it uses

Compute Engine instances to run your code.

Flex applications must always have at least a single VM instance running, and end

up costing money around the clock. 


11.2. Interacting with App Engine

Understanding of the underlying organizational concepts that App Engine uses,


Create a simple “Hello, world!” application for App Engine, deploy it, and verify

that it works.

11.2.1. Building an application in App Engine Standard

App Engine Standard is a fully managed environment where your code runs inside

a special sandbox rather than a full virtual machine.

Build your “Hello, world!” application using one of the approved languages.

Make sure you have the right tools installed.

Creating an application

Focusing on nothing more than a “Hello, world!”

Whenever you send a GET HTTP request to this handler, it sends back “Hello from App Engine!”


Note: We will use flask for this class

Put this code into a file called main.py

A way you tell App Engine how to configure an application is with an app.yaml file.

YAML (Yet Another Markup Language) 


Easily readable syntax for some structured data that looks a lot like Markdown.

app.yaml name is a special file that App Engine looks for when you deploy your application.

Deploying another service

New service as a new chunk of code, and you need to make sure you have a safe



11.2.2. On App Engine Flex

App Engine Standard is limited to some of the popular programming languages and

runs inside a sandbox environment, 

App Engine Flex is based on Docker containers.

You can use any programming language you want.

Creating an application

11.3. Scaling your application

Scaling and instance configuration, App Engine Standard and App Engine Flex have

a few differences. 


11.3.1. Scaling on App Engine Standard


App Engine Standard has quite a few scaling options that you can fine-tune so they

fit your needs.

Automatic scaling

Default scaling option is automatic.

App Engine will decide when to turn on new instances.

Number of concurrent requests.

Longest a given request should wait around in a queue.

Number of instances that can be idle at any given time. 

Idle instances

App Engine Standard instances are only chunks of CPU and memory rather than a full

virtual machine.

Standard provides a way for you to decide the minimum and maximum number of

instances that can sit idle waiting for requests before being turned off.


Set the minimum and maximum idle instances both to 1, then App Engine will turn
off instances until there’s exactly one sitting idle waiting for requests.

YAML file

runtime: python27

api_version: 1

service: default

automatic_scaling:

  min_idle_instances: 2

  max_idle_instances: 3

Pending latency

Latency is a measure of delay In a network, latency measures the time it takes for

some data to get to its destination across the network request to App Engine.

Servers handle the request and ultimately route it to a specific instance.

No instance is available.

Sit in a queue for a bit until an instance becomes available. 

Lots of people making requests to the service.

App Engine immediately queues up requests to be processed.

App Engine can turn on more instances.


App Engine the minimum and/or maximum amount of time sitting in this queue,

pending latency.

More than the maximum pending latency. turn on more instances. 

Minimum pending latency App Engine turn on more instances. 

Concurrent requests
Instances can handle more than one request at a time.

Number of requests happening at once (level of concurrency) is another metric to

use when autoscaling. 

Concurrency level as a way to trigger turning more instances on or off.

Target for how many requests an instance can handle at the same time.

 App Engine handle eight requests concurrently all the way up to 80.

Basic scaling

Slimmed-down version of automatic scaling.

Max number of instances how long idle instance  before turning it off.

How long those instances should sit idle before App Engine turns them off. 

Manual scaling

 App Engine exactly how many instances you want running at a given time.



Requests are routed pool of machines. overwhelmed requests time out.

11.3.2. Scaling on App Engine Flex

App Engine Flex is based on Docker containers and Compute Engine VMs, Scaling

configurations autoscaling Compute Engine

Automatic scaling

App Engine Flex  scaling your services up and down.

Control the number of VM instances that can be running at any given time.

Maximum number of instances avoid application scaling out of control. 

Manual scaling

App Engine Flex has an option to decide up front exactly how many VM instances

to run for your service.

11.3.3. Choosing instance configurations

Number of instances and how to scale them, and I’ve asked you to think of instances

as chunks of CPU and memory.

Configurations suit your application, starting with App Engine Standard.

App Engine Standard instance classes
App Engine Standard running your code in a special sandbox environment.

Use a setting called instance_class in your app.yaml file.


By default, automatically scaled services use F1 instances. 

App Engine Flex instances

Because App Engine Flex is based on Docker containers and Compute Engine.

11.4.1. Storing data with Cloud Datastore

Storing data Google Cloud Platform has many services available.

Access these services from inside App Engine.

Connect to the services from inside your App Engine application.

Cloud Datastore is a nonrelational storage system that stores documents and provides

ways to query them.

Prebaked into App Engine with APIs built into the runtime. 

Python, App Engine Standard provides a Datastore API package called ndb, which acts as an ORM (object-relational mapping) tool. 

11.4.3. Deferring tasks

Your code has some work to do that doesn’t need to be done right away but instead

could be delayed.

Sending an email or recalculating some difficult result.

Something that takes a while and can be done in the background. 

App Engine system built-in  to push work off until later, called Task Queues.

Send a response telling the user that they should get an email soon.

11.4.4. Splitting traffic

Trigger a deployment without making the new version live yet. 

Run multiple versions side by side, do hot switch-overs between versions.


Shifting traffic from one version to another over the course of the day?

Traffic splitting, control what percentage of traffic goes to which version. 

11.5. Understanding pricing

App Engine are priced, costs for  the services  discussed computing costs.

Built on  Compute Engine instances, costs same as Compute Engine,

11.6. When should I use App Engine?

App Engine’s environments are like entirely separate computing platforms,


11.6.1. Flexibility

App Engine Flex offers levels of flexibility similar to those of Compute Engine or

Kubernetes Engine, App Engine Standard is far more limited.

11.6.2. Complexity

App Engine Standard, runtime environments limitations.

App Engine Flex, more complexity

11.6.3. Performance

Flex relies on Compute Engine VMs, performance good as you’ll get on a cloud

computing platform.

11.6.4. Cost

App Engine Flex has pricing that’s identical to Compute Engine.

App Engine controls the scaling. 

Summary

  • App Engine is a fully managed cloud computing environment
  • simplifies the overhead needed for all applications 

  • App Engine has two different environments:

  • Standard, which is the more restricted environment,

  • Flex, which is less restrictive and container-based.

  • App Engine Standard supports a specific set of language runtimes,

  • App Engine Flex supports anything tin a Docker container.

  • App Engine can contain lots of services.

  • Each service contain several versions run concurrently.

  • Underneath application’s services are virtualized computing resources.

  • The main draw is automatic scalability

  • configure to meet the needs of most modern applications.

  • Standard comes with a specific set of managed services,

  • accessed via client libraries provided to the runtime directly

  • App Engine pricing is based on the hourly consumption of the

  • underlying compute resources.

  • App Engine Flex, prices are identical to Compute Engine instance pricing.



https://codelabs.developers.google.com/codelabs/cloud-app-engine-python3/#0


No comments:

Post a Comment

Disable Billing

Search for Billing Manage billing accounts Go to MYPROJECTS CLICK ON THE 3 BUTTON Actions Then hit disable