
Instance scaling
While an application is running, incoming requests are routed to an existing or new instance of the appropriate service/version. The scaling type of a service/version controls how instances are created. Scaling settings are configured in the app.yaml
file. There are two scaling types:
Manual scaling
- A service with manual scaling runs continuously the exact same number of instances irrespective of the load level. This allows tasks such as complex initializations and applications that rely on the state of the memory over time.
Automatic scaling
- Automatic scaling is based on request rate, response latencies, and other application metrics.
Monitoring resource usage
The Instances page of the Cloud Platform Console provides visibility into how instances are performing. You can see the memory and CPU usage of each instance, uptime, number of requests, and other statistics. You can also manually initiate the shutdown process for any instance.
Logging
When you write to stdout or stderr, entries appear in the Cloud Platform Console Logs page.
Communication between services
Services can communicate with other services and external applications in various ways. The simplest approach is to send HTTP requests to a service by including its name in the URL: <service-name>.app-id.appspot.com
. If you require secure communication between services, you can authorize requests.
Services can also communicate via Cloud Pub/Sub. Pub/Sub provides reliable asynchronous many-to-many messaging between processes, including App Engine. These processes can be individual instances of your application, services, or even external applications.
Services and external applications can also share data stored in databases such as Cloud Datastore, Cloud SQL, or third-party databases.
Node.js
Recently at Boyle Software we had the opportunity to use Google App Engine Flexible on a project for one of our clients (Vroom.com) and found it quite nice to work with. We were especially excited about using it’s new Node.js option..
The Node.js runtime is the software stack responsible for installing your application’s code and its dependencies and running your application. The standard runtime is declared in app.yaml
as runtime: nodejs
:
1 2 3 |
<span class="pln">runtime</span><span class="pun">:</span><span class="pln"> nodejs env</span><span class="pun">:</span><span class="pln"> flex </span> |
Runtimes in the flexible environment are built using Docker.
Engines
The default Node.js engine aims to be the latest LTS release. You can specify a different Node.js version in your application’s package.json
file by using the engines
field.
The following example configures the runtime to use the latest Node 8 release.
1 2 3 4 5 6 |
<span class="pun">{</span><span class="pln"> </span><span class="str">"engines"</span><span class="pun">:</span> <span class="pun">{</span><span class="pln"> </span><span class="str">"node"</span><span class="pun">:</span> <span class="str">"8.x"</span><span class="pln"> </span><span class="pun">}</span> <span class="pun">}</span> |
Dependencies
During deployment, the runtime can use either npm or yarn to fetch and install the dependencies declared in your package.json
file. By default the runtime uses npm install
, but if a yarn.lock
file is present, the runtime will use yarn install
instead. If you want to force the runtime to use npm
, you can list the yarn.lock
file in the skip_files
section of your app.yaml
file.
Application startup
The runtime starts your application by using npm start
, which uses the command specified in package.json
. For example:
1 2 3 4 |
<span class="str">"scripts"</span><span class="pun">:</span> <span class="pun">{</span><span class="pln"> </span><span class="str">"start"</span><span class="pun">:</span> <span class="str">"node app.js"</span> <span class="pun">}</span> |
Your start script should start a web server that responds to HTTP requests on the port specified by the PORT
environment variable, typically 8080.
Get started with Google App Engline Flexible environment today here: https://cloud.google.com/appengine/docs/flexible/