So now when we have written all this code,
let's look at how to scale your application, using
modules. Modules are a serious heavy-duty function within App
Engine and they allow you to partition your code, have
better control over scalability, and do version control and
online upgrades. For simplicity, we did not use modules when
building Conference Central, but it is something we strongly
suggest you start exploring on your own. By looking at
the online documentation. All right, let's get started. When
you create an App Engine application using modules, it will
conceptually be structured like a tree. At the very
top, we have the root, which is your application, and
your application is made up of a number of
modules, in this example two. A module groups three concepts.
Code related to the module. The instance class that
should be used to execute the code, this is the
speed of the CPU, and the amount of memory
that should be used. The scalability parameters including the number
of instances to start and their life cycle. So
a module groups code to be executed, the performance resources
and the scalability and instance life cycle you want to
have. Each module can then have a number of different
versions associated with it. A version is essentially a
version of your code being maintained in the module. So,
after you have deployed your application into production you
can deploy new versions of your code and you
can have multiple versions running in parallel, and gradually
migrate traffic from the old version to the new. This
capability allows you to do version upgrades without having
to bring down your application. Something that is extremely difficult
to do without App Engine. And finally, there are
instances. An instance is what actually executes the application code.
And if you want to scale your application, App Engine
can fire up more instances to manage the additional load.
And since the instance class and the number of instances
define the performance and scalability of a module. The capacity of
your application depends on the instances class and the number
of instances you run. This is configured on the module
level, and that is exactly what we will look at
now. How to configure a module. let's start looking at two
scaling options for modules. Manual Scaling and Automatic Scaling.
These specify different scale up and scale down characteristics of
instances. Manual scaling allows you to create instances that are
always up and running and that never terminates. Because of
this, they don't have the ten minute execution limit
with they process tasks or cron jobs. Since they are
always up and running, they can work for any amount
of time. And that means that they are great to
use if you have long running background tasks or
cron jobs. The only thing you need to configure for
manual scaling is the number of instances you want
the module to start. That's manual scaling. Let's now talk
about automatic scaling. Automatic scaling is the option that
allows App Engine to automatically scale your application up and
down depending on the load. The first two options
you can specify for automatic scaling is the minimum and
maximum number of idle instances you want. What does
this mean? Why would you want to have idle instances?
Well, instances have a startup time and if you
don't want your users to wait for the response while
your application needs to scale up by starting new
instances, and it could be good to have idle instances
available if your application needs to scale up. So your
users don't have to wait for more instances to start.
Let's now look at latency. Where you can specify
the minimum and maximum pending latency allowed for requests. These
parameters work as follows. So let's say a request comes
into your application right here, and there's no instance available
to process it. Then it is put in a wait
queue. App Engine now has a decision to make. When
to scale up your application using more instances. Well, to
begin with, it will wait for some time to see
if any of the existing instances become available to
process their request. This is called a minimum pending
latency, if this time passes, App Engine is considering
starting a new instance to manage the request. And if
the next pending latency time expires, then a new
instance would be started for sure to manage the load.
This is how App Engine performs a scale up
of your application. Rather than specifying a number for these
four parameters, you can all set them to automatic.
In such case, App Engine will set them according
to the dynamic analysis it performs. Finally, both manual
and automatic scaling have a common configuration element. Which is
the Instance Class. The instance class specifies the speed
of the CPU and the amount of memory to
use for each of the instances started. Check out
the developer documentation for more details on the options available.
As you probably see by now, modules is
heavy-duty stuff. And in addition to the scaling options
we looked at, it also has versions that
we briefly touched on. Versions allow you to perform
online upgrades on part of your system without
any service disruption. Without App Engine, doing automatic scaling
and dynamic upgrades are extremely difficult problems to solve.
So make sure that you use this great functionality.